Configuration scripts use non-portabl which #999

Open
opened 2026-10-05 04:57:53 +02:00 by adam · 3 comments
Owner

One way of going about it is:

From 0c33396e34d26c3c1ba5af90167b875147b0b49a Mon Sep 17 00:00:00 2001
From: malc clamky@hotmail.com
Date: Fri, 10 Sep 2021 03:12:42 +0300
Subject: [PATCH] Replace "which" with "command -v"

The former is some kind of user program with an unspecified interface,
the latter is POSIX.

configure | 6 +++---
znc-buildmod.cmake.in | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/configure b/configure
index eeb0af1c..258f5ab6 100755
--- a/configure
+++ b/configure
@@ -18,9 +18,9 @@

http://stackoverflow.com/questions/18993438/shebang-env-preferred-python-version

http://stackoverflow.com/questions/12070516/conditional-shebang-line-for-different-versions-of-python

""":"
-which python3 >/dev/null 2>&1 && exec python3 "$0" "$@"
-which python >/dev/null 2>&1 && exec python "$0" "$@"
-which python2 >/dev/null 2>&1 && exec python2 "$0" "$@"
+command -v python3 >/dev/null 2>&1 && exec python3 "$0" "$@"
+command -v python >/dev/null 2>&1 && exec python "$0" "$@"
+command -v python2 >/dev/null 2>&1 && exec python2 "$0" "$@"
echo "Error: configure wrapper requires python"
exec echo "Either install python, or use cmake directly"
":"""
diff --git a/znc-buildmod.cmake.in b/znc-buildmod.cmake.in
index 632b5aba..915d77fe 100755
--- a/znc-buildmod.cmake.in
+++ b/znc-buildmod.cmake.in
@@ -18,9 +18,9 @@

http://stackoverflow.com/questions/18993438/shebang-env-preferred-python-version

http://stackoverflow.com/questions/12070516/conditional-shebang-line-for-different-versions-of-python

""":"
-which python3 >/dev/null 2>&1 && exec python3 "$0" "$@"
-which python >/dev/null 2>&1 && exec python "$0" "$@"
-which python2 >/dev/null 2>&1 && exec python2 "$0" "$@"
+command -v python3 >/dev/null 2>&1 && exec python3 "$0" "$@"
+command -v python >/dev/null 2>&1 && exec python "$0" "$@"
+command -v python2 >/dev/null 2>&1 && exec python2 "$0" "$@"
echo "Error: znc-buildmod requires python"
exec echo "Either install python, or use cmake directly"
":"""

2.33.0

One way of going about it is: From 0c33396e34d26c3c1ba5af90167b875147b0b49a Mon Sep 17 00:00:00 2001 From: malc <clamky@hotmail.com> Date: Fri, 10 Sep 2021 03:12:42 +0300 Subject: [PATCH] Replace "which" with "command -v" The former is some kind of user program with an unspecified interface, the latter is POSIX. --- configure | 6 +++--- znc-buildmod.cmake.in | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/configure b/configure index eeb0af1c..258f5ab6 100755 --- a/configure +++ b/configure @@ -18,9 +18,9 @@ # http://stackoverflow.com/questions/18993438/shebang-env-preferred-python-version # http://stackoverflow.com/questions/12070516/conditional-shebang-line-for-different-versions-of-python """:" -which python3 >/dev/null 2>&1 && exec python3 "$0" "$@" -which python >/dev/null 2>&1 && exec python "$0" "$@" -which python2 >/dev/null 2>&1 && exec python2 "$0" "$@" +command -v python3 >/dev/null 2>&1 && exec python3 "$0" "$@" +command -v python >/dev/null 2>&1 && exec python "$0" "$@" +command -v python2 >/dev/null 2>&1 && exec python2 "$0" "$@" echo "Error: configure wrapper requires python" exec echo "Either install python, or use cmake directly" ":""" diff --git a/znc-buildmod.cmake.in b/znc-buildmod.cmake.in index 632b5aba..915d77fe 100755 --- a/znc-buildmod.cmake.in +++ b/znc-buildmod.cmake.in @@ -18,9 +18,9 @@ # http://stackoverflow.com/questions/18993438/shebang-env-preferred-python-version # http://stackoverflow.com/questions/12070516/conditional-shebang-line-for-different-versions-of-python """:" -which python3 >/dev/null 2>&1 && exec python3 "$0" "$@" -which python >/dev/null 2>&1 && exec python "$0" "$@" -which python2 >/dev/null 2>&1 && exec python2 "$0" "$@" +command -v python3 >/dev/null 2>&1 && exec python3 "$0" "$@" +command -v python >/dev/null 2>&1 && exec python "$0" "$@" +command -v python2 >/dev/null 2>&1 && exec python2 "$0" "$@" echo "Error: znc-buildmod requires python" exec echo "Either install python, or use cmake directly" ":""" -- 2.33.0 <!-- github-sync-id:992765367 -->
Author
Owner

For which system does your patch fix it?

For which system does your patch fix it? <!-- github-comment-id:939989931 -->
Author
Owner

Alexey Sokolov @.***> writes:

For which system does your patch fix it?

For my mac mini with a crux ppc, where /bin/sh is ash. For thys arch
should i choose to switch /bin/sh from bash to ash.

What is "which" btw? Is there a standard that desclibes it?

Alexey Sokolov ***@***.***> writes: > For which system does your patch fix it? > For my mac mini with a crux ppc, where /bin/sh is ash. For thys arch should i choose to switch /bin/sh from bash to ash. What is "which" btw? Is there a standard that desclibes it? <!-- github-comment-id:940006467 -->
Author
Owner

Arch Linux also doesn't have which in a minimal installation (although which is in the base-devel group).

The provided patch should be the correct solution. From POSIX command:

-v Write a string to standard output that indicates the pathname or command that will be used by the shell, in the current shell execution environment [...] to invoke command_name, but do not invoke command_name. [...] Otherwise, no output shall be written and the exit status shall reflect that the name was not found.

Arch Linux also doesn't have `which` in a minimal installation (although `which` is in the `base-devel` group). The provided patch should be the correct solution. From POSIX [`command`](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html): > `-v` Write a string to standard output that indicates the pathname or command that will be used by the shell, in the current shell execution environment [...] to invoke `command_name`, but do not invoke `command_name`. [...] Otherwise, no output shall be written and the exit status shall reflect that the name was not found. <!-- github-comment-id:1076656024 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/znc#999