Copyright (C) 2000, by
Carlo Wood, Run on IRC <carlo@alinoe.com> RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
@command{Which} takes one or more arguments. For each of its arguments it prints to stdout the full path of the executables that would have been executed when this argument had been entered at the shell prompt. It does this by searching for an executable or script in the directories listed in the environment variable @env{PATH} using the same algorithm as @command{bash(1)}.
The synopsis to invoke @command{which} is
which [options] [--] programname [...]
alias which='alias | which -i'
.
@command{Which} returns the number of failed arguments, or -1 when no `programname' was given.
A useful way to use this utility is by adding an alias for @command{which} like the following:
alias which='which --tty-only --show-tilde --show-dot'
This will print the readable ~/ and ./ when starting which from your prompt, while still printing the full path when used from a script:
> which q2 ~/bin/q2 > echo `which q2` /home/carlo/bin/q2
Aliases are also supported, through the use of an alias for which itself. An example alias for which that is using this feature is as follows:
alias which='alias | which --tty-only --read-alias --show-tilde --show-dot'
This will print the output of alias for each alias that matches one of the given arguments. For example, using this alias on itself in a tcsh:
$ alias which alias \| /usr/bin/which -i !\* $ which which which (alias | /usr/bin/which -i !*) /usr/bin/which
The @env{HOME} directory is determined by looking for the @env{HOME} environment variable, which aborts when this variable doesn't exist. @command{Which} will consider two equivalent directories to be different when one of them contains a path with a symbolic link.
@command{bash(1)}
Jump to: @ - a - b - c - d - e - i - o - r - s
This document was generated on 4 November 2000 using texi2html 1.56k.