diff --git a/NEWS b/NEWS index 1e11d4448..ac9151cb1 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,9 @@ Any uppercase BUG_* names are modernish shell bug IDs. a subshell. Types can now safely be defined in subshells and defined conditionally as in 'if condition; then enum ...; fi'. +- Single digits can now be compared lexically in [[ ... ]] with the + < and > operators. + 2021-12-16: - Changed the default selection of compiled-in /opt/ast/bin built-in libcmd diff --git a/src/cmd/ksh93/sh/lex.c b/src/cmd/ksh93/sh/lex.c index 73f2e44b3..7293c9e95 100644 --- a/src/cmd/ksh93/sh/lex.c +++ b/src/cmd/ksh93/sh/lex.c @@ -1264,7 +1264,7 @@ breakloop: { /* check for numbered redirection */ n = state[0]; - if((c=='<' || c=='>') && isadigit(n)) + if(!lp->lex.intest && (c=='<' || c=='>') && isadigit(n)) { c = sh_lex(lp); lp->digits = (n-'0'); diff --git a/src/cmd/ksh93/tests/bracket.sh b/src/cmd/ksh93/tests/bracket.sh index 1eedb86bd..785ea9756 100755 --- a/src/cmd/ksh93/tests/bracket.sh +++ b/src/cmd/ksh93/tests/bracket.sh @@ -461,5 +461,59 @@ do e=${c%%:*} (($?==e)) || err_exit "test \( $c \) not working" done +# ====== +# [[ ... ]] shouldn't error out when using '>' and '<' with or without a +# space in between strings (including when a number is handled as a string). +exp=0 +$SHELL -c '[[ 3>2 ]]'; got=$? +((exp == got)) || err_exit "[[ ... ]] cannot handle '3>2'" \ + "(expected $exp, got $got)" +$SHELL -c '[[ 3 > 2 ]]'; got=$? +((exp == got)) || err_exit "[[ ... ]] cannot handle '3 > 2'" \ + "(expected $exp, got $got)" +$SHELL -c '[[ 1<2 ]]'; got=$? +((exp == got)) || err_exit "[[ ... ]] cannot handle '1<2'" \ + "(expected $exp, got $got)" +$SHELL -c '[[ 1 < 2 ]]'; got=$? +((exp == got)) || err_exit "[[ ... ]] cannot handle '1 < 2'" \ + "(expected $exp, got $got)" +$SHELL -c '[[ ab ]]'; got=$? +((exp == got)) || err_exit "[[ ... ]] cannot handle 'c>b'" \ + "(expected $exp, got $got)" +$SHELL -c '[[ c > b ]]'; got=$? +((exp == got)) || err_exit "[[ ... ]] cannot handle 'c > b'" \ + "(expected $exp, got $got)" +exp=1 +$SHELL -c '[[ 3<2 ]]' || got=$? +((exp == got )) || err_exit "[[ ... ]] cannot handle '3<2'" \ + "(expected $exp, got $got)" +$SHELL -c '[[ 3 < 2 ]]' || got=$? +((exp == got )) || err_exit "[[ ... ]] cannot handle '3 < 2'" \ + "(expected $exp, got $got)" +$SHELL -c '[[ 1>2 ]]'; got=$? +((exp == got )) || err_exit "[[ ... ]] cannot handle '1>2'" \ + "(expected $exp, got $got)" +$SHELL -c '[[ 1 > 2 ]]'; got=$? +((exp == got )) || err_exit "[[ ... ]] cannot handle '1 > 2'" \ + "(expected $exp, got $got)" +$SHELL -c '[[ a>b ]]'; got=$? +((exp == got)) || err_exit "[[ ... ]] cannot handle 'a>b'" \ + "(expected $exp, got $got)" +$SHELL -c '[[ a > b ]]'; got=$? +((exp == got)) || err_exit "[[ ... ]] cannot handle 'a > b'" \ + "(expected $exp, got $got)" +$SHELL -c '[[ c