">danny@compgen.com writes:
> Okay, here's my small contribution. I call it 'path', and it will
> print out all matching executables in the PATH list. Of course, the top
> line is the one the shell uses.
...
> so "path ls" produces:
> /home/danny/bin/ls
> /bin/ls
I have something similar in ksh, handling wildcards and
also some other things:
function path # search for each command, file pattern, alias, or builtin
{
typeset arg dir w lscmd=echo
set +f # +o trackall
case "$1" in -l) lscmd='ls -lt'; shift;; esac
case $# in
0) (IFS=:; for dir in $PATH; do ls -sd $dir; done);;
*) for arg; do case "$arg" in
*[?*]*) (IFS=:; for dir in $PATH; do [[ -d "$dir" ]] || continue
\cd $dir; IFS=' '; set -- $arg
[[ -f "$1" ]] && { echo "$dir:"; $lscmd "$@"; }
done) ;;
*) (set -o trackall
w=$(whence -v "$arg"); print -r "$w"; typeset -f "$arg"
[[ "$w" = *?(an\ alias|a\ function)* ]] && continue
w=$(whence -vp "$arg")
[[ $w = */* ]] && echo "On PATH, $w") ;;
esac; done;;
esac; :
}
With that defined, I have this example:
% path *wm
/usr/local/bin:
pbmtocmuwm
/usr/local/bin/X11:
9wm gwm olvwm
/usr/local/netpbm/bin:
pbmtocmuwm
/usr/local/bin/pbmplus:
pbmtocmuwm
/usr/openwin/bin:
ctwm olwm twm
/usr/dt/bin:
dtwm
/usr/local-sol1/bin/X11:
olvwm swm tvtwm vtwm
And while we are on path-related functions, here is a set
of functions useful for eliminating bogus or duplicate
entries from a path variable.
# simppath PATHVAR -- eliminate bad or duplicate directories in PATHVAR.
# For the sake of X, dirs are truncated at "/%" before testing existence.
function simppath {
typeset d t IFS ret p="${1-$PATH}"
case "$p" in
:*)p=".$p";;
*::*)p="${p%%::*}:.:${p#*::}";;
*:)p="$p.";;
esac
IFS=:
for d in $p; do
t="${d%%"/%"*}"
if [[ -d "$t" ]]; then
[[ -L "$t" ]] && d=$(truedir "$t")"${d#"$t"}"
[[ "$d" = *?/ ]] && d="${d%/}"
[[ ":$ret:" = *":$d:"* ]] || ret="$ret:$d"
fi
done
echo "${ret#:}"
}
function truedir { \cd "$1">/dev/null&&/usr/bin/pwd;}
function repath { eval "export ${1-PATH}=\$(simppath \"\$${1-PATH}\")";}
With those defined, "repath" will fix your PATH variable,
and "repath LD_LIBRARY_PATH" will fix that variable.
Caveat: these are only well-tested in ksh under Solaris.
--
To unsubscribe: mail ">majordomo@ale.org with "unsubscribe ale" in message body.