From 51df036f26cf0ab4c4c758f44d64569568793e43 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Sat, 13 Mar 2021 23:17:08 +0000 Subject: [PATCH] options feature test tweaks src/cmd/ksh93/features/options: - SHOPT_TEST_L: Use 'env test' instead of '/bin/test' to run external 'test', as the direct path is unportable. Create a test symlink and verify the positive case as well as the negative. - SHOPT_SYSRC: Use if...then..fi instead of ... && ... for the last test to avoid a non-zero exit status of the script, which outputs a spurious 'no' result like this: iffe: test: cross{ ... }end ... no - Add comments for clarity and to make the SHOPT_* names greppable. Related: https://github.com/ksh93/ksh/issues/219 --- src/cmd/ksh93/features/options | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/cmd/ksh93/features/options b/src/cmd/ksh93/features/options index f8eaceddc..4150ffcbf 100644 --- a/src/cmd/ksh93/features/options +++ b/src/cmd/ksh93/features/options @@ -1,6 +1,6 @@ # SHOPT_* option probe -tst cross{ +tst note{ SHOPT_* option probe }end cross{ : check for shell magic #! cat > "$EXECROOT/file$$" </dev/null 2>&1 option DEVFD $? case `echo a | tr a '\012' | wc -l` in @@ -34,10 +36,17 @@ tst cross{ #test -x /bin/pfexec -o -x /usr/bin/pfexec #option PFSH $? - /bin/test ! -l . 2> /dev/null + # if external 'test' supports lowercase -l as equivalent to -L, enable + # SHOPT_TEST_L so ksh supports it for compatibility with local scripts + ln -s /dev/null "$EXECROOT/link$$" + env test -l "$EXECROOT/link$$" 2>/dev/null && env test ! -l . 2>/dev/null option TEST_L $? - test -f /etc/ksh.kshrc -o -f /etc/bash.bashrc && - option SYSRC 0 + rm -f "$EXECROOT/link$$" + + # if one of these exists, make SHOPT_SYSRC load /etc/ksh.kshrc by default + if test -f /etc/ksh.kshrc || test -f /etc/bash.bashrc + then option SYSRC 0 + fi }end cat{