To get the absolute pathname of a command, Korn shell users can run
users have type
On other shells, use
But those will only show the first directory in your
with that command.
If you want to find other commands with the same name in other directories,
the standard which
won't show them to you.
on the CD-ROM will - if you use its - a
So will the bash
command type -all
On my system, the /usr/bin
directory holds a Berkeley-like version of a
directory holds System V versions.
is first in my path, but it's good to know if there's
also a System V version.
also lets you see if there are both local and system versions of
the same command in your path.
Here's the script.
The name ends in a z
because many UNIX versions already have a
# COMMAND THAT TESTS FOR EXECUTABLE FILES... SYSTEM-DEPENDENT:
# REPLACE NULL FIELD IN $PATH WITH A .
fixpath="`echo $PATH | sed \
-e 's/^:/.:/' \
-e 's/::/:.:/g' \
IFS=": " # SET $IFS (COLON, SPACE, TAB) FOR PARSING $PATH
where="" # ZERO OUT $where
# IF DIRECTORY HAS EXECUTABLE FILE, ADD IT TO LIST:
for direc in $fixpath
do $testx $direc/$command && where="$where $direc/$command"
case "$where" in
?*) echo $where ;; # IF CONTAINS SOMETHING, OUTPUT IT
command "fixes" your PATH
It replaces a null directory name (
in the middle of the
or a single
at the start or end of the PATH
which stands for the current directory.
The null member is changed to the
relative pathname for the current directory, a dot (1.21
so the direc
shell variable in the loop won't be empty.
In line 12, the double quotes (
) have colon, space, and tab
characters between them.
This sets the
variable to split the "fixed" search path, at the colon
into separate directories
That's a useful way to handle any colon-separated list.