diff --git a/NEWS b/NEWS index 91083160c..c2efd9976 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,9 @@ Any uppercase BUG_* names are modernish shell bug IDs. - Fixed a crash that could occur when a KEYBD trap was set and a multi-line command substitution was input in an interactive shell. +- The shell linter's warnings for obsolete arithmetic operators in [[ ... ]] + and unnecessary variable expansion in ((...)) have been improved. + 2021-11-24: - The --posix mode was amended to stop the '.' command (but not 'source') from diff --git a/src/cmd/ksh93/data/lexstates.c b/src/cmd/ksh93/data/lexstates.c index 2465e268a..19a8dd7c4 100644 --- a/src/cmd/ksh93/data/lexstates.c +++ b/src/cmd/ksh93/data/lexstates.c @@ -430,13 +430,13 @@ const char e_lexsyntax2[] = "syntax error: `%s' %s"; const char e_lexsyntax3[] = "syntax error at line %d: duplicate label %s"; const char e_lexsyntax4[] = "syntax error at line %d: invalid reference list"; const char e_lexsyntax5[] = "syntax error at line %d: `<<%s' here-document not contained within command substitution"; -const char e_lexwarnvar[] = "line %d: variable expansion makes arithmetic evaluation less efficient"; +const char e_lexwarnvar[] = "line %d: in '((%s))', using '$' is slower and can introduce rounding errors"; const char e_lexlabignore[] = "line %d: label %s ignored"; const char e_lexlabunknown[] = "line %d: %s unknown label"; const char e_lexobsolete1[] = "line %d: `...` obsolete, use $(...)"; const char e_lexobsolete2[] = "line %d: -a obsolete, use -e"; const char e_lexobsolete3[] = "line %d: '=' obsolete, use '=='"; -const char e_lexobsolete4[] = "line %d: %s within [[ ... ]] obsolete, use ((...))"; +const char e_lexobsolete4[] = "line %d: [[ ... %s ... ]] obsolete, use ((... %s ...))"; const char e_lexobsolete5[] = "line %d: set %s obsolete"; const char e_lexobsolete6[] = "line %d: `{' instead of `in' is obsolete"; const char e_lexusebrace[] = "line %d: use braces to avoid ambiguities with $id[...]"; diff --git a/src/cmd/ksh93/sh/lex.c b/src/cmd/ksh93/sh/lex.c index 073162bc2..b77577b87 100644 --- a/src/cmd/ksh93/sh/lex.c +++ b/src/cmd/ksh93/sh/lex.c @@ -1389,7 +1389,32 @@ breakloop: if(lp->lex.testop2) { if(lp->lexd.warn && (c&TEST_ARITH)) - errormsg(SH_DICT,ERROR_warn(0),e_lexobsolete4,shp->inlineno,state); + { + char *alt; + switch(c) + { + case TEST_EQ: + alt = "=="; /* '-eq' --> '==' */ + break; + case TEST_NE: + alt = "!="; /* '-ne' --> '!=' */ + break; + case TEST_LT: + alt = "<"; /* '-lt' --> '<' */ + break; + case TEST_GT: + alt = ">"; /* '-gt' --> '>' */ + break; + case TEST_LE: + alt = "<="; /* '-le' --> '<=' */ + break; + case TEST_GE: + alt = ">="; /* '-ge' --> '>=' */ + break; + } + errormsg(SH_DICT, ERROR_warn(0), e_lexobsolete4, + shp->inlineno, state, alt); + } if(c&TEST_STRCMP) lp->lex.incase = 1; else if(c==TEST_REP) diff --git a/src/cmd/ksh93/sh/parse.c b/src/cmd/ksh93/sh/parse.c index 0f7373184..bf4ba8edf 100644 --- a/src/cmd/ksh93/sh/parse.c +++ b/src/cmd/ksh93/sh/parse.c @@ -303,7 +303,7 @@ static Shnode_t *getanode(Lex_t *lp, struct argnod *ap) else { if(sh_isoption(SH_NOEXEC) && (ap->argflag&ARG_MAC) && paramsub(ap->argval)) - errormsg(SH_DICT,ERROR_warn(0),e_lexwarnvar,lp->sh->inlineno); + errormsg(SH_DICT,ERROR_warn(0),e_lexwarnvar,lp->sh->inlineno,ap->argval); t->ar.arcomp = 0; } return(t);