which-2.14 and alternatives

The presence / absence of the which program in the main LFS book is probably one of the most contentious issues we have on the mailing lists. It has resulted in at least one flame war in the recent past. To hopefully put an end to this once and for all, we here present two of the options for equipping your system with "which".

The first option is to install the actual GNU program which.

Introduction to which

Download location (HTTP):       http://ftp.gnu.org/gnu/which/which-2.14.tar.gz
Download location (FTP):        ftp://ftp.gnu.org/gnu/which/which-2.14.tar.gz
Version used:                   2.14
Package size:                   110 KB
Estimated Disk space required:  719 KB

Installation of which

Install which by running the following commands:

./configure --prefix=/usr &&
make &&
make install

Contents

The which package contains which.

Description

which

which shows the full path of (shell) commands.

The 'which' script

The second option (for those who don't want to install the program) is to create a simple script:

cat > /usr/bin/which << "EOF"
#!/bin/bash
type -p "$@"
EOF
chmod 755 /usr/bin/which
chown root:root /usr/bin/which

This should generally work OK and is probably the easiest solution for boxes which don't need a good user environment to work in.