#!/usr/local/bin/perl # # emulate BSD which program # # pat@jaameri.gsfc.nasa.gov (patrick m. ryan) # eval "exec /usr/bin/perl -S $0 $*" if $running_under_some_shell; require 'getopts.pl'; &Getopts('v'); @path=split(/:/,$ENV{PATH}); foreach $exec (@ARGV) { # see if this command is an alias $cmd = "$ENV{SHELL} -c 'alias $exec'"; open(CMD,"$cmd |"); chop($alias = ); close CMD; $ret=$?>>8; if (!$ret && $alias) { if ($alias =~ /(\S+)\s*=\s*(\S+)/) { $alias = $2; } print "$exec aliased to $alias\n"; } # now search the path foreach $dir (@path) { $bin="$dir/$exec"; $bin =~ s|/+|/|oig; if ( -f $bin ) { print $bin; if ( ! -x $bin ) { print "\tnot executable"; } print "\n"; if ($opt_v) { system "ls -l $bin"; } } } } exit 0; # Local Variables: # mode: perl # End: