To get the absolute pathname of a command, Korn shell users can run
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,
won't show them to you.
on the CD-ROM will - if you use its
So will the
On my system, the
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
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
It replaces a null directory name (
in the middle of the
or a single
at the start or end of the
which stands for the current directory.
The null member is changed to the
relative pathname for the current directory, a dot (
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.