shell: better support of [[ ]] bashism

Still rather rudimentary for ash

function                                             old     new   delta
binop                                                433     589    +156
check_operator                                        65     101     +36
done_word                                            736     769     +33
test_main                                            405     418     +13
parse_stream                                        2227    2238     +11
ops_texts                                            124     133      +9
ops_table                                             80      86      +6
run_pipe                                            1557    1562      +5
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 8/0 up/down: 269/0)             Total: 269 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2020-10-31 03:34:07 +01:00
parent 112453acf2
commit d2241f5902
13 changed files with 209 additions and 24 deletions

View File

@ -207,17 +207,17 @@
#define IF_BASH_SUBSTR IF_ASH_BASH_COMPAT
/* BASH_TEST2: [[ EXPR ]]
* Status of [[ support:
* We replace && and || with -a and -o
* && and || work as they should
* = is glob match operator, not equality operator: STR = GLOB
* (in GLOB, quoting is significant on char-by-char basis: a*cd"*")
* == same as =
* add =~ regex match operator: STR =~ REGEX
* TODO:
* singleword+noglob expansion:
* v='a b'; [[ $v = 'a b' ]]; echo 0:$?
* [[ /bin/n* ]]; echo 0:$?
* -a/-o are not AND/OR ops! (they are just strings)
* quoting needs to be considered (-f is an operator, "-f" and ""-f are not; etc)
* = is glob match operator, not equality operator: STR = GLOB
* (in GLOB, quoting is significant on char-by-char basis: a*cd"*")
* == same as =
* add =~ regex match operator: STR =~ REGEX
* ( ) < > should not have special meaning
*/
#define BASH_TEST2 (ENABLE_ASH_BASH_COMPAT * ENABLE_ASH_TEST)
#define BASH_SOURCE ENABLE_ASH_BASH_COMPAT
@ -11823,7 +11823,8 @@ simplecmd(void)
tokpushback = 1;
goto out;
}
wordtext = (char *) (t == TAND ? "-a" : "-o");
/* pass "&&" or "||" to [[ ]] as literal args */
wordtext = (char *) (t == TAND ? "&&" : "||");
#endif
case TWORD:
n = stzalloc(sizeof(struct narg));