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.
The first option is to install the actual GNU which package.
Development versions of BLFS may not build or run some packages properly if LFS or dependencies have been updated since the most recent stable versions of the books.
下载地址(HTTP):https://ftpmirror.gnu.org/which/which-2.25.tar.gz
MD5 校验和:60140cb2637634e4f4e68c2e98c6a07b
大小:200 KB
预计所需磁盘空间:1.3 MB
预计构建时间:小于 0.1 SBU
Install which by running the following commands:
./configure --prefix=/usr && make
This package does not come with a test suite.
Now, as the root user:
make install
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.