Skip to content

Commit 2dece79

Browse files
committed
install-from-source: avoid using which before it is installed
The `which` executable must often be installed because it is missing from many a Docker image. Therefore, it won't _really_ work if one checks `which which` to figure out whether `which` is installed. Let's avoid this by using `type`, which is a shell builtin for most shells. The `type` utility is specified in the POSIX standard, as per https://pubs.opengroup.org/onlinepubs/9699919799/utilities/type.html, yet neither command-line options nor output is standardized. The only thing we _can_ rely on is the exit status. Note: _Technically_, this poses a change of behavior, as `which` resolves only to executables that are on the `PATH` while `type` will also happily report shell builtins. However, this is a net improvement: If running the script in, say, BusyBox, where many of the common utilities (including `which`!) are shell builtins, we would like to avoid forcefully installing the packages without need. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2bc4b4a commit 2dece79

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/linux/Packaging.Linux/install-from-source.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ install_packages() {
6363

6464
for package in $packages; do
6565
# Ensure we don't stomp on existing installations.
66-
if [ ! -z $(which $package) ]; then
66+
if type $package >/dev/null 2>&1; then
6767
continue
6868
fi
6969

0 commit comments

Comments
 (0)