use my which (was: which/type & built-ins)
Maarten Litmaath
maart at cs.vu.nl
Sat Jan 6 07:03:53 AEST 1990
...if you want speed and no .cshrc quirks. Manual follows. See alt.sources
(or comp.sources.misc archive soon) or email.
WHICH(1) USER COMMANDS WHICH(1)
NAME
which - give alias, function or path expansion of command
SYNOPSIS
which [ -i ] [ -a ] [ -- ] [ command ]
DESCRIPTION
Which provides the user with the full expansion of the com-
mand argument, be it either an alias, a shell function or an
executable file (default). To enable search for aliases and
shell functions the user should supply the `-i' (= interac-
tive) flag. In that case which expects as standard input the
expansion of the alias or shell function. If the standard
input is empty or the `-i' flag has not been given, which
will try to locate command in the user's PATH. The interac-
tive mode is easily used by setting an alias like the fol-
lowing:
alias which alias !\$ \| /usr/local/bin/which -i !\*
in csh, or
alias which eval alias '\"\$$#\" |' \
/usr/local/bin/which -i '${1+"$@"}'
in shells which are supersets of sh and which know aliases.
If your shell has shell functions, you can use the following
function:
which()
{
eval last=\"\$$#\"
set | sed -n "/^$last(){$/,/^}$/p" |
/usr/local/bin/which -i ${1+"$@"}
}
If the `-a' (= all) flag is given, which will not stop after
the first `match', but search for all occurrences of command
in the user's PATH. The `--' flag can be used to end the
list of options: the next argument (if present) will be
taken as command, even if it starts with a `-'. Which [-i]
[-a] [--] without further arguments prints the user's PATH
broken up into its components, one per line.
This new version of the which command is not a csh script.
Being an executable it is much faster, and not sourcing
.cshrc it gives a true picture of one's aliases.
EXAMPLE
% alias
which alias !$ | /usr/local/bin/which -i !*
% which which
which alias !$ | /usr/local/bin/which -i !*
% which -a which
which alias !$ | /usr/local/bin/which -i !*
/usr/local/bin/which
/usr/ucb/which
%
--
1755 EST, Dec 14, 1992: Henry Spencer is put on a one-way mission to the moon.|
Maarten Litmaath @ VU Amsterdam: maart at cs.vu.nl, uunet!mcsun!botter!maart
More information about the Comp.unix.questions
mailing list