home *** CD-ROM | disk | FTP | other *** search
- # Usage: which <command>
- # Tries to find out what is actually being run when command is typed.
- # Does the following, in order :
- # Looks at aliases
- # Looks to see if it is a module command.
- # Looks in <Run$Path>
-
- die "Usage: which <command>\n" unless ($#ARGV==0);
-
- $command = $ARGV[0];
-
- # Try to get Alias$<command>
- if (($alias = $ENV{"Alias\$$command"}) || ($alias = $ENV{"AlIaS\$$command"}))
- {
- die "$command : Aliased to $alias\n";
- }
-
- # Try to open a pipe to Help <command>
- if (open(HELP, "help $command|"))
- {
- $line = <HELP>;
- close(HELP);
- $line = substr($line, 1);
- die "$command : builtin command\n" unless ($line eq "No help found.\n");
- }
-
- # Look through Run$Path to see if a file named command is visible.
- if ($path = $ENV{"Run\$Path"})
- {
- @entries = split(",", $path);
- foreach $dir (@entries)
- {
- $dir =~ s/[ | ]//g;
- $dir = $dir.$command;
- if (-e $dir)
- {
- print "Found in Run\$Path - $dir\n";
- exec("%Info $dir");
- }
- }
- }
-
- die "$command : Not found\n";
-