From 42d1651108831c391dca5b5284ca9ba2c4ae94ce Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sun, 23 Aug 2020 19:20:33 +0100 Subject: [PATCH] iffe: fix broken shell detection; allow building on NetBSD 9.0 The shell detection test assumed that any shell that has $RANDOM and isn't bash must be ksh and have the 'print' built-in command. This broke iffe on NetBSD 9.0 sh, which has $RANDOM but not 'print'. src/cmd/INIT/iffe.sh: - Rewrite shell detection test to test for features actually used by iffe. "$shell" can now have the values 'bsh' for an ancient pre-POSIX Bourne shell, 'bash' for bash, 'ksh' for a shell with 'let', 'typeset -u' and 'print' (ksh88, ksh93, mksh, pdksh, zsh), and 'posix' for another POSIX or POSIX-ish shell with modern command substitutions and parameter substitutions. (The 'posix' value currently is not actively checked for anywhere, but avoids unnecessary use of bsh fallbacks.) --- src/cmd/INIT/iffe.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/cmd/INIT/iffe.sh b/src/cmd/INIT/iffe.sh index 27aaa4159..0586fbfec 100644 --- a/src/cmd/INIT/iffe.sh +++ b/src/cmd/INIT/iffe.sh @@ -649,16 +649,19 @@ protoflags= puthdr= putlib= pragma= -case $RANDOM in -$RANDOM)shell=bsh +case `eval 'v=NOposixNO; w=$(export "w=$v"; echo "${w%%NO}"); echo "${w##NO}"' 2>/dev/null` in +posix) shell=posix # or at least POSIX-ish + case $BASH_VERSION in + [1-9]*) shell=bash ;; + esac + case `eval 'PATH=/dev/null && let i=93-5 && typeset -u v=ksh$i && print -r - "$v"' 2>/dev/null` in + KSH88) shell=ksh ;; # also pdksh, mksh, zsh + esac + ;; +*) shell=bsh # ancient pre-POSIX Bourne shell ($executable .) 2>/dev/null || executable='test -r' ($exists .) 2>/dev/null || exists='test -r' ;; -*) case $BASH_VERSION in - ?*) shell=bash ;; - *) shell=ksh ;; - esac - ;; esac reallystatic= reallystatictest=