Bob Camp     Cygnus Technical Consulting            12/11/1998
Copyright Bob Camp 1998

Which Version 0.16.0

Which tells you which program is used and is a little more sophisticated
than the usual versions.  Main features are:

o Reporting on shell.
o Reporting on paths.
o Correcting paths.
o Searching along appropriate paths for:
  o Executables.
  o Libraries.
  o Header files.
  o Manual pages.
  o Info pages.
  o Source files/directories.
  o Document files/directories.
  o General file search.
  o Ten user configurable path and search patterns.
o Setup from /etc/which.conf and ~/.which files.
o Allows configuration for extended path search.
o Works even if $PATH etc is not set.
o Finds non-executables, ie broken links or executable bit not set.
o Extended globbing allowed on search pattern.
o Follows and reports links.
o Follows and reports aliases.
o Reports object type.
o Reports shared libraries.
o Can specify shell on command line, even if it is not on the system.
o Supports bash, sh, tcsh, csh, ksh, ash, zsh (aiming to add more).
o Mechanisms to communicate with the starting shell for accurate reporting.
o Can accurately synthesize shell from command line.
o Works even with no setup.

Sound to good to be true?  It is, you need GNU bash, version 2.02.1 or
later.

Which V0.14 has been on alpha release for some time and does not appear to
have any major problems.

If you supply information for your favourite shell then it to can be
supported.

Main changes from V0.14.0 are;

o Add zsh.

o Some minor bug fixes.

o Improved reporting and made it more consistent.

o Significantly extended reporting with -i (was -j) option.

o Improved reporting of multiple references to output item.

o Minor changes to operation of -M and -d options.

o Add -n, native mode.

o Allow system wide configuration file to be located anywhere.


Installation
------------

Typically; locate which in /usr/bin, gzip which.1 and put it in
/usr/man/man1.

At its simplest you need only ensure that line one of the 'which' script
points to bash.  If you do this 'which' will identify aliases and functions
by running the appropriate shell and getting it to report what is setup.
This will suffice for most of the time.  However, 'which' is really very
useful when things do not work quite as expected.  For example if an
executable is not found.  Here you may just use 'which -ld filename' and
'which' will report anything with the correct name and follow all links,
reporting if they point to non-existant or non-executable files.

To get the best from 'which' you should use '/etc/which.conf' (or a file
pointed to by $WHICH_CONF) to define extended search paths, $PATH_A,
$MANPATH_A etc.  For example use:

find / -name bin -type d

to identify all bin directories on your system and edit this into a colon
(or space) delimited list to set PATH_A.

Alternatively run the setup tool like this:

./which-setup > config

Then edit the file 'config' and include it in your 'which.conf' file.

When the -b option is used $PATH_A will be appended to $PATH, $MANPATH_A to
$MANPATH etc.  If these are correctly set up in /etc/which.conf then 'which
-b' will report correctly even if the user PATHs are null.

Take the time to setup 'which' as an alias in your .bashrc using:

alias which='(echo $$ oldpwd=$OLDPWD; alias; enable; declare -f) |
/usr/bin/which -g'

This alias is suitable for zsh.

and in your .tcshrc using:

which = '(echo $$ shell=$0; alias; builtins | /usr/bin/tr '\'' '\'' '\''\n'\'') | ~/bin/which -g'

These aliases allow the shell to tell 'which' what aliases and functions
are defined and what builtins are in use.  The '$$' is required because
'which' will ignore the information if the PID is wrong.  The
'oldpwd=$OLDPWD' part allows 'which' to expand '~-' correctly for bash.
Note the use of absolute paths that allow 'which' to get started even if
$PATH is wrong.  (Once started it can usually manage ok.)

If an alias or function is defined or modified in the current shell then
'which' will know about it when used.

Options -0 through -9 are definable by the user.  Typically in ~/.which and
can be set up for your favourite search.  These may even be included in the
-W (whereis) option.  See the manual for full details.


Bugs reports
------------

Please read the bug list at http://www.hadron.demon.co.uk
before reporting, so as to avoid duplication.  Then mail bugs to
which-bug@hadron.demon.co.uk.

Patches should be sent to which-patch@hadron.demon.co.uk.

It is possible that I will not have time to answer all mails since I have
limited time for programming work.  If you do not receive a reply to your
mail then please accept my thanks and appreciation for your valuable
contributions here.


Copying
-------

This software and documentation is Copyright Bob Camp 1998 and issued as
freeware under the GNU General Public Licence.  It comes with absolutely no
warranty.  It is used entirely at the user's own risk.  See the enclosed
'COPYING' file for full details.

---
