From 3ede73aa33801c7a60a364518e213566ed2e1d6c Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Fri, 4 Sep 2020 20:51:29 +0200 Subject: [PATCH] fix "$-" expansion for posix option (re: 921bbcae) In the SHOPT_BASH code, the -o posix option was given a '\374' (0xFC, 252) single-letter option character. Reasons unclear. The 'set' builtin doesn't accept it. It can be omitted and the option still works. And it caused the "$-" expansion (listing active short-form options) to include that invalid high-bit character if the -o posix option is active, which is clearly wrong. src/cmd/ksh93/sh/args.c: optksh[], flagval[]: - Remove '\374' one-letter option equivalent for SH_POSIX. src/cmd/ksh93/tests/options.sh: - Add test verifying that '-o posix' does not affect "$-". --- src/cmd/ksh93/sh/args.c | 3 +-- src/cmd/ksh93/tests/options.sh | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cmd/ksh93/sh/args.c b/src/cmd/ksh93/sh/args.c index b4fe735a8..db0556225 100644 --- a/src/cmd/ksh93/sh/args.c +++ b/src/cmd/ksh93/sh/args.c @@ -54,13 +54,12 @@ static char *null; /* The following order is determined by sh_optset */ -static const char optksh[] = PFSHOPT "\374" "DircabefhkmnpstuvxBCGEl" HFLAG; +static const char optksh[] = PFSHOPT "DircabefhkmnpstuvxBCGEl" HFLAG; static const int flagval[] = { #if SHOPT_PFSH SH_PFSH, #endif - SH_POSIX, SH_DICTIONARY, SH_INTERACTIVE, SH_RESTRICTED, SH_CFLAG, SH_ALLEXPORT, SH_NOTIFY, SH_ERREXIT, SH_NOGLOB, SH_TRACKALL, SH_KEYWORD, SH_MONITOR, SH_NOEXEC, SH_PRIVILEGED, SH_SFLAG, SH_TFLAG, diff --git a/src/cmd/ksh93/tests/options.sh b/src/cmd/ksh93/tests/options.sh index 666f327a2..b6344a8eb 100755 --- a/src/cmd/ksh93/tests/options.sh +++ b/src/cmd/ksh93/tests/options.sh @@ -531,4 +531,15 @@ print '. ./dotfile' > envfile print $'alias print=:\nprint foobar' > dotfile [[ $(ENV=/.$PWD/envfile $SHELL -i -c : 2>/dev/null) == foobar ]] && err_exit 'files source from profile does not process aliases correctly' +# ====== +# test that '-o posix' option (not having a letter) does not affect "$-" expansion +( + command set +o posix 2>/dev/null + opt1=$- + command set -o posix 2>/dev/null + opt2=$- + [[ $opt1 == "$opt2" ]] +) || err_exit '-o posix option affects $- expansion' + +# ====== exit $((Errors<125?Errors:125))