Multiple executables in path (Was: NON-SOURCE POSTINGS CONSIDERED HARMFUL!)
Tom Christiansen
tchrist at convex.COM
Sat Jan 19 21:56:24 AEST 1991
>From the keyboard of brnstnd at kramden.acf.nyu.edu (Dan Bernstein):
:Hmmm. I've always been satisfied with the speed of
:
: alias which 'echo `echo "$PATH" | tr : '\''\012'\'' | sed -e '\''s+$+/\!:1+'\'' -e '\''s:^:/.[.]:'\''` | sed '\''s:/../:/:g'\'''
But it doesn't do the same thing as mine does, Dan. Yours is more like this:
for $file (@ARGV) {
for $dir (split(/:/,$ENV{'PATH'})) {
print $path,"\n" if -x ($path="$dir/$file");
}
}
except that it uses many more processes, runs more slowly, and is
significantly more difficult to read and thus maintain.
But as I said, the original code does something different: it doesn't just
tell you which paths lead to a particular command. Rather, it produces a
complete list of all commands in your $PATH with more than one path to
them, except for those duplicates that are just there due to symlinks to
the same executable and by the same name, such as /etc/foo ->
/usr/etc/foo. That's why the $files{$name, $dev, $ino} array is kept. I
doubt you can do the last part with a csh alias, and even if you could, I
wouldn't want to try to make sense out of it, unless of course it just
pointed to my script. :-)
--tom
--
"Hey, did you hear Stallman has replaced /vmunix with /vmunix.el? Now
he can finally have the whole O/S built-in to his editor like he
always wanted!" --me (Tom Christiansen <tchrist at convex.com>)
More information about the Alt.sources.d
mailing list