home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / unix / unixcmds_1 / BIN / which < prev    next >
Encoding:
Text File  |  1993-06-10  |  984 b   |  44 lines

  1. # Usage: which <command>
  2. # Tries to find out what is actually being run when command is typed.
  3. # Does the following, in order :
  4. #    Looks at aliases
  5. #    Looks to see if it is a module command.
  6. #    Looks in <Run$Path>
  7.  
  8. die "Usage: which <command>\n" unless ($#ARGV==0);
  9.  
  10. $command = $ARGV[0];
  11.  
  12. # Try to get Alias$<command>
  13. if (($alias = $ENV{"Alias\$$command"}) || ($alias = $ENV{"AlIaS\$$command"}))
  14. {
  15.     die "$command : Aliased to $alias\n";
  16. }
  17.     
  18. # Try to open a pipe to Help <command>
  19. if (open(HELP, "help $command|"))
  20. {
  21.     $line = <HELP>;
  22.     close(HELP);
  23.     $line = substr($line, 1);
  24.     die "$command : builtin command\n" unless ($line eq "No help found.\n");
  25. }
  26.  
  27. # Look through Run$Path to see if a file named command is visible.
  28. if ($path = $ENV{"Run\$Path"})
  29. {
  30.     @entries = split(",", $path);
  31.     foreach $dir (@entries)
  32.     {
  33.         $dir =~ s/[ |    ]//g;
  34.         $dir = $dir.$command;
  35.         if (-e $dir)
  36.         {
  37.             print "Found in Run\$Path - $dir\n";
  38.             exec("%Info $dir");
  39.         }
  40.     }
  41. }
  42.  
  43. die "$command : Not found\n";
  44.