$SHELL is the user's login shell.  It may change on every login.
It's often a POSIX shell but not always and there's no need to
require that, given that we never need to spawn the user's preferred
interactive shell.

For executing shell scripts, we use POSIX_SHELL_PROG.  This is
determined at compile time, usually as /bin/sh.

Commit c34c6cc58 ([nroff]: Improve shell behavior check., 2024-12-07)
used $SHELL to work around an issue caused by a POSIX non-compliant
POSIX_SHELL_PROG=/bin/sh on Solaris 10.

We care about the currently executing shell, so use a POSIX subshell
instead of "$SHELL -c" to test exactly that, even if the user has
changed their login shell or overridden $SHELL.

Originally reported at https://github.com/fish-shell/fish-shell/issues/12602
---
 ChangeLog                        | 12 ++++++++++++
 contrib/eqn2graph/eqn2graph.sh   |  7 +++----
 contrib/grap2graph/grap2graph.sh |  7 +++----
 contrib/pic2graph/pic2graph.sh   |  7 +++----
 src/preproc/eqn/neqn.sh          |  7 +++----
 src/roff/nroff/nroff.sh          | 11 ++++-------
 6 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index bc766c5f5..434932bd6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2026-04-03  Johannes Altmanninger <[email protected]>
+
+       * src/roff/nroff/nroff.sh:
+       * contrib/eqn2graph/eqn2graph.sh:
+       * contrib/grap2graph/grap2graph.sh:
+       * contrib/pic2graph/pic2graph.sh:
+       * src/preproc/eqn/neqn.sh:
+       * src/roff/nroff/nroff.sh:
+
+       When detecting POSIX-non-compliant shells, spawn subshell instead
+       of $SHELL.
+
 2026-03-31  G. Branden Robinson <[email protected]>
 
        * tmac/an.tmac: Ensure that the register
diff --git a/contrib/eqn2graph/eqn2graph.sh b/contrib/eqn2graph/eqn2graph.sh
index 8f6f5c9f7..b6649d4e4 100644
--- a/contrib/eqn2graph/eqn2graph.sh
+++ b/contrib/eqn2graph/eqn2graph.sh
@@ -35,10 +35,9 @@ badshell=yes
 # Solaris 10 /bin/sh is so wretched that it not only doesn't support
 # standard parameter expansion, but it also writes diagnostic messages
 # to the standard output instead of standard error.
-if [ -n "$SHELL" ]
-then
-  "$SHELL" -c 'prog=${0##*/}' >/dev/null 2>&1 && badshell=
-fi
+(
+  prog=${0##*/}
+) >/dev/null 2>&1 && badshell=
 
 if [ -n "$badshell" ]
 then
diff --git a/contrib/grap2graph/grap2graph.sh b/contrib/grap2graph/grap2graph.sh
index cda70b1ab..f2d1fb39e 100644
--- a/contrib/grap2graph/grap2graph.sh
+++ b/contrib/grap2graph/grap2graph.sh
@@ -34,10 +34,9 @@ badshell=yes
 # Solaris 10 /bin/sh is so wretched that it not only doesn't support
 # standard parameter expansion, but it also writes diagnostic messages
 # to the standard output instead of standard error.
-if [ -n "$SHELL" ]
-then
-  "$SHELL" -c 'prog=${0##*/}' >/dev/null 2>&1 && badshell=
-fi
+(
+  prog=${0##*/}
+) >/dev/null 2>&1 && badshell=
 
 if [ -n "$badshell" ]
 then
diff --git a/contrib/pic2graph/pic2graph.sh b/contrib/pic2graph/pic2graph.sh
index 6edf80002..d07dbe821 100644
--- a/contrib/pic2graph/pic2graph.sh
+++ b/contrib/pic2graph/pic2graph.sh
@@ -41,10 +41,9 @@ badshell=yes
 # Solaris 10 /bin/sh is so wretched that it not only doesn't support
 # standard parameter expansion, but it also writes diagnostic messages
 # to the standard output instead of standard error.
-if [ -n "$SHELL" ]
-then
-  "$SHELL" -c 'prog=${0##*/}' >/dev/null 2>&1 && badshell=
-fi
+(
+  prog=${0##*/}
+) >/dev/null 2>&1 && badshell=
 
 if [ -n "$badshell" ]
 then
diff --git a/src/preproc/eqn/neqn.sh b/src/preproc/eqn/neqn.sh
index 12864a6eb..5b0518ab5 100644
--- a/src/preproc/eqn/neqn.sh
+++ b/src/preproc/eqn/neqn.sh
@@ -24,10 +24,9 @@ badshell=yes
 # Solaris 10 /bin/sh is so wretched that it not only doesn't support
 # standard parameter expansion, but it also writes diagnostic messages
 # to the standard output instead of standard error.
-if [ -n "$SHELL" ]
-then
-  "$SHELL" -c 'prog=${0##*/}' >/dev/null 2>&1 && badshell=
-fi
+(
+  prog=${0##*/}
+) >/dev/null 2>&1 && badshell=
 
 if [ -n "$badshell" ]
 then
diff --git a/src/roff/nroff/nroff.sh b/src/roff/nroff/nroff.sh
index 05c293632..1e26d2d41 100644
--- a/src/roff/nroff/nroff.sh
+++ b/src/roff/nroff/nroff.sh
@@ -27,10 +27,9 @@ badshell=yes
 # Solaris 10 /bin/sh is so wretched that it not only doesn't support
 # standard parameter expansion, but it also writes diagnostic messages
 # to the standard output instead of standard error.
-if [ -n "$SHELL" ]
-then
-  "$SHELL" -c 'prog=${0##*/}' >/dev/null 2>&1 && badshell=
-fi
+(
+  prog=${0##*/}
+) >/dev/null 2>&1 && badshell=
 
 if [ -n "$badshell" ]
 then
@@ -73,10 +72,8 @@ do
       -[abCEikpRStUvzZ]*)
         if test -n "$badshell"
         then
-          # POSIX doesn't actually require $SHELL, but fortunately at
-          # least one craptastic non-conforming shell offers it.
           echo "$prog: option cluster '$thisarg' not supported with" \
-            "POSIX-non-conforming shell '$SHELL'" >&2
+            "POSIX-non-conforming shell" >&2
           exit 2
         fi
         remainder=${thisarg#-?}
-- 
2.51.0.167.g6ad8021821.dirty


Reply via email to