Which-2.23 and Alternatives

#### Gaming Linux® From Scratch - Version 13.0

### Chapter 8. Basic X11 Software

- Prev

  libxcb-1.17.0

- Next

  libpng-1.6.55

- Up
- Home

# Which-2.23 and Alternatives

The presence or absence of the which program in the main LFS book is probably one of the most contentious issues on the mailing lists. It has resulted in at least one flame war in the past. To hopefully put an end to this once and for all, presented here are two options for equipping your system with which. The question of which “which” is for you to decide.

## Introduction to GNU Which

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

- Download: https://ftpmirror.gnu.org/gnu/which/which-2.23.tar.gz

## Installation of Which

Install which by running the following commands:

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

Now, as the `root` user:

    make install

## Command Explanations

### Note

Run ./configure --help for a full list of options.

## Contents

Installed Program: which
Installed Libraries: None
Installed Directories: None

### Short Descriptions

which | shows the full path of (shell) commands installed in your `PATH`

## The 'which' Script

The second option (for those who don't want to install the package) is to create a simple script (execute as the `root` user):

    cat > /usr/bin/which << "EOF" &&
    #!/bin/bash
    type -pa "$@" | head -n 1 ; exit ${PIPESTATUS[0]}
    EOF

    chmod -v 755 /usr/bin/which &&
    chown -v root:root /usr/bin/which

This should work OK and is probably the easiest solution for most cases, but is not the most comprehensive implementation.

### Note

Some build systems [1] expect which to support options which can alter the string of the file path of a given program. This installation can therefore trip up those build systems. If in doubt, install the GNU version instead of the script.

[1] A notable example is pkgsuite.

- Prev

  libxcb-1.17.0

- Next

  libpng-1.6.55

- Up
- Home