The test suite was insisting on using /bin/sh -n for syntax checking,
which meant that if /bin/sh wasn’t one of the short list of shells
whose -n is known to work, we would skip all of the syntax-check
tests, even if some other shell was available that would work.

Instead do like _AS_DETECT_BETTER_SHELL, and loop over possible
shells, starting with $SHELL and going on to a hardwired list of
known-good possibilities.  The result is written to the substitution
variable @SHELL_N@ and the testsuite uses that.

(Should we invoke AC_PATH_PROG on the result of the search if it’s not
already absolute?)

        * Search for a shell whose -n mode is known to
        work, instead of just checking /bin/sh.  Set @SHELL_N@ to
        what we find.
        * tests/ Propagate @SHELL_N@ to testsuite.
        * tests/ (AT_CHECK_SHELL_SYNTAX): Use $SHELL_N instead
        of hardcoding /bin/sh.  Update test for usable shell -n.
        (AT_CHECK_AUTOCONF): Update test for usable shell -n.
        * tests/ Update test for usable shell -n.
---     | 39 +++++++++++++++++++++++++--------------
 tests/ |  2 +-
 tests/   |  6 +++---
 tests/   |  2 +-
 4 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/ b/
index 8ff9f729..e9f0da92 100644
--- a/
+++ b/
@@ -35,9 +35,9 @@ AC_SUBST([RELEASE_YEAR])
-# We use '/bin/sh -n script' to check that there are no syntax errors
-# in the scripts.  Although incredible, there are /bin/sh that go into
-# endless loops with '-n', e.g., SunOS's:
+# We use 'sh -n script' to check that there are no syntax errors
+# in the scripts.  Although incredible, there are sh implementations
+# that go into endless loops with '-n', e.g., SunOS's:
 #   $ uname -a
 #   SunOS ondine 4.1.3 2 sun4m unknown
@@ -52,27 +52,38 @@ AB_INIT
 #   $ time sh -nx
 #   ^Csh -nx  3,67s user 0,03s system 63% cpu 5,868 total
-# Also, some implementations of /bin/sh (e.g., Solaris 8) are soooo slow
+# Also, some implementations (e.g., Solaris 8) are soooo slow
 # that they are unusable on large scripts like our testsuite.
+# So we must identify a shell whose -n can safely be used.
-# So before using '/bin/sh -n' to check our scripts, we first check
-# that '/bin/sh -n' is known to not have these problems.
-AC_CACHE_CHECK([whether /bin/sh -n is known to work], [ac_cv_sh_n_works],
-[if (
+AC_CACHE_CHECK([for a shell whose -n mode is known to work],
+               [ac_cv_sh_working_n],
+# Start by trying the shell that autoconf decided to use for this script,
+# follow with a hardwired list of shells that are known to work and can
+# be identified as such, starting with the ones with the fewest
+# syntactic extensions.  Unfortunately, several shells that are also
+# known to work can't be easily identified (e.g. BSD sh, dash).
+# Try ksh93, which is often buggy, and plain ksh and sh last.
+for cand_sh in "$SHELL" pdksh bash zsh ksh93 ksh sh
+  if (
-    /bin/sh -c '
+    "$cand_sh" -c '
       test ${BASH_VERSION+y} || # Bash
       test ${KSH_VERSION+y} || # pdksh
       test ${ZSH_VERSION+y} || # zsh
       test -n "${.sh.version}" # ksh93; put this last since its syntax is dodgy
   ) 2>/dev/null
-then ac_cv_sh_n_works=yes
-else ac_cv_sh_n_works=no
+  then
+    ac_cv_sh_working_n="$cand_sh"
+    break
+  fi
+AC_SUBST([SHELL_N], [$ac_cv_sh_working_n])
 AC_MSG_CHECKING([for characters that cannot appear in file names])
diff --git a/tests/ b/tests/
index ec2a4167..079e35c6 100644
--- a/tests/
+++ b/tests/
@@ -24,7 +24,7 @@ EGREP='@EGREP@'
 # We need to know if sh -n is ok.
 # Check whether the underlying system can manage some unusual
 # symbols in file names.
diff --git a/tests/ b/tests/
index 88a24e77..8496f55c 100644
--- a/tests/
+++ b/tests/
@@ -50,8 +50,8 @@ AT_CHECK([$at_diff "$1" "$2"])
 # otherwise, do nothing.  ksh93 -n also spits outs loads of warnings
 # about older constructs, but we don't care about the warnings.
-[AT_SKIP_IF([test "$ac_cv_sh_n_works" != yes])
-AT_CHECK([/bin/sh -n $1], [], [], [ignore])])
+[AT_SKIP_IF([test "$SHELL_N" = none])
+AT_CHECK(["$SHELL_N" -n $1], [], [], [ignore])])
 [AT_CHECK([autom4te_perllibdir=$abs_top_srcdir/lib $PERL -c 
@@ -216,7 +216,7 @@ cp "$abs_top_srcdir/tests/statesave.m4" aclocal.m4
 # were running too fast.
 [AT_CHECK_M4([autoconf --force $1], [$2], [$3], [$4])
-if test -s configure && test "$ac_cv_sh_n_works" = yes; then
+if test -s configure && test "$SHELL_N" != none; then
diff --git a/tests/ b/tests/
index b95bdcf5..9d3c7183 100644
--- a/tests/
+++ b/tests/
@@ -45,7 +45,7 @@ AT_BANNER([Executables (autoheader, autoupdate...).])
 AT_SETUP([Syntax of the shell scripts])
-AT_CHECK([test "$ac_cv_sh_n_works" = yes || exit 77])
+AT_CHECK([test "$SHELL_N" != none || exit 77])
 # Specify the absolute name of the tool, as some shells don't honor PATH when
 # running `sh PROG'.

Reply via email to