diff options
-rw-r--r-- | shell/ash.c | 54 | ||||
-rw-r--r-- | shell/ash_test/ash-arith/arith-bash1.right | 2 | ||||
-rwxr-xr-x | shell/ash_test/ash-arith/arith-bash1.tests | 5 | ||||
-rw-r--r-- | shell/ash_test/ash-vars/var_bash1.right | 14 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/var_bash1.tests | 18 | ||||
-rw-r--r-- | shell/ash_test/ash-vars/var_bash2.right | 10 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/var_bash2.tests | 24 |
7 files changed, 115 insertions, 12 deletions
diff --git a/shell/ash.c b/shell/ash.c index 9024d783d..3651929c2 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -8470,8 +8470,10 @@ static const struct builtincmd builtintab[] = { | |||
8470 | { BUILTIN_SPEC_REG ":", truecmd }, | 8470 | { BUILTIN_SPEC_REG ":", truecmd }, |
8471 | #if ENABLE_ASH_BUILTIN_TEST | 8471 | #if ENABLE_ASH_BUILTIN_TEST |
8472 | { BUILTIN_REGULAR "[", testcmd }, | 8472 | { BUILTIN_REGULAR "[", testcmd }, |
8473 | #if ENABLE_ASH_BASH_COMPAT | ||
8473 | { BUILTIN_REGULAR "[[", testcmd }, | 8474 | { BUILTIN_REGULAR "[[", testcmd }, |
8474 | #endif | 8475 | #endif |
8476 | #endif | ||
8475 | #if ENABLE_ASH_ALIAS | 8477 | #if ENABLE_ASH_ALIAS |
8476 | { BUILTIN_REG_ASSG "alias", aliascmd }, | 8478 | { BUILTIN_REG_ASSG "alias", aliascmd }, |
8477 | #endif | 8479 | #endif |
@@ -8534,17 +8536,25 @@ static const struct builtincmd builtintab[] = { | |||
8534 | { BUILTIN_REGULAR "wait", waitcmd }, | 8536 | { BUILTIN_REGULAR "wait", waitcmd }, |
8535 | }; | 8537 | }; |
8536 | 8538 | ||
8537 | 8539 | /* Should match the above table! */ | |
8538 | #define COMMANDCMD (builtintab + 5 + \ | 8540 | #define COMMANDCMD (builtintab + \ |
8539 | 2 * ENABLE_ASH_BUILTIN_TEST + \ | 8541 | 2 + \ |
8540 | ENABLE_ASH_ALIAS + \ | 8542 | 1 * ENABLE_ASH_BUILTIN_TEST + \ |
8541 | ENABLE_ASH_JOB_CONTROL) | 8543 | 1 * ENABLE_ASH_BUILTIN_TEST * ENABLE_ASH_BASH_COMPAT + \ |
8542 | #define EXECCMD (builtintab + 7 + \ | 8544 | 1 * ENABLE_ASH_ALIAS + \ |
8543 | 2 * ENABLE_ASH_BUILTIN_TEST + \ | 8545 | 1 * ENABLE_ASH_JOB_CONTROL + \ |
8544 | ENABLE_ASH_ALIAS + \ | 8546 | 3) |
8545 | ENABLE_ASH_JOB_CONTROL + \ | 8547 | #define EXECCMD (builtintab + \ |
8546 | ENABLE_ASH_CMDCMD + \ | 8548 | 2 + \ |
8547 | ENABLE_ASH_BUILTIN_ECHO) | 8549 | 1 * ENABLE_ASH_BUILTIN_TEST + \ |
8550 | 1 * ENABLE_ASH_BUILTIN_TEST * ENABLE_ASH_BASH_COMPAT + \ | ||
8551 | 1 * ENABLE_ASH_ALIAS + \ | ||
8552 | 1 * ENABLE_ASH_JOB_CONTROL + \ | ||
8553 | 3 + \ | ||
8554 | 1 * ENABLE_ASH_CMDCMD + \ | ||
8555 | 1 + \ | ||
8556 | ENABLE_ASH_BUILTIN_ECHO + \ | ||
8557 | 1) | ||
8548 | 8558 | ||
8549 | /* | 8559 | /* |
8550 | * Search the table of builtin commands. | 8560 | * Search the table of builtin commands. |
@@ -10048,6 +10058,9 @@ simplecmd(void) | |||
10048 | union node *vars, **vpp; | 10058 | union node *vars, **vpp; |
10049 | union node **rpp, *redir; | 10059 | union node **rpp, *redir; |
10050 | int savecheckkwd; | 10060 | int savecheckkwd; |
10061 | #if ENABLE_ASH_BASH_COMPAT | ||
10062 | smallint double_brackets_flag = 0; | ||
10063 | #endif | ||
10051 | 10064 | ||
10052 | args = NULL; | 10065 | args = NULL; |
10053 | app = &args; | 10066 | app = &args; |
@@ -10058,13 +10071,30 @@ simplecmd(void) | |||
10058 | 10071 | ||
10059 | savecheckkwd = CHKALIAS; | 10072 | savecheckkwd = CHKALIAS; |
10060 | for (;;) { | 10073 | for (;;) { |
10074 | int t; | ||
10061 | checkkwd = savecheckkwd; | 10075 | checkkwd = savecheckkwd; |
10062 | switch (readtoken()) { | 10076 | t = readtoken(); |
10077 | switch (t) { | ||
10078 | #if ENABLE_ASH_BASH_COMPAT | ||
10079 | case TAND: /* "&&" */ | ||
10080 | case TOR: /* "||" */ | ||
10081 | if (!double_brackets_flag) { | ||
10082 | tokpushback = 1; | ||
10083 | goto out; | ||
10084 | } | ||
10085 | wordtext = (char *) (t == TAND ? "-a" : "-o"); | ||
10086 | #endif | ||
10063 | case TWORD: | 10087 | case TWORD: |
10064 | n = stzalloc(sizeof(struct narg)); | 10088 | n = stzalloc(sizeof(struct narg)); |
10065 | n->type = NARG; | 10089 | n->type = NARG; |
10066 | /*n->narg.next = NULL; - stzalloc did it */ | 10090 | /*n->narg.next = NULL; - stzalloc did it */ |
10067 | n->narg.text = wordtext; | 10091 | n->narg.text = wordtext; |
10092 | #if ENABLE_ASH_BASH_COMPAT | ||
10093 | if (strcmp("[[", wordtext) == 0) | ||
10094 | double_brackets_flag = 1; | ||
10095 | else if (strcmp("]]", wordtext) == 0) | ||
10096 | double_brackets_flag = 0; | ||
10097 | #endif | ||
10068 | n->narg.backquote = backquotelist; | 10098 | n->narg.backquote = backquotelist; |
10069 | if (savecheckkwd && isassignment(wordtext)) { | 10099 | if (savecheckkwd && isassignment(wordtext)) { |
10070 | *vpp = n; | 10100 | *vpp = n; |
diff --git a/shell/ash_test/ash-arith/arith-bash1.right b/shell/ash_test/ash-arith/arith-bash1.right new file mode 100644 index 000000000..b261da18d --- /dev/null +++ b/shell/ash_test/ash-arith/arith-bash1.right | |||
@@ -0,0 +1,2 @@ | |||
1 | 1 | ||
2 | 0 | ||
diff --git a/shell/ash_test/ash-arith/arith-bash1.tests b/shell/ash_test/ash-arith/arith-bash1.tests new file mode 100755 index 000000000..b37b7302d --- /dev/null +++ b/shell/ash_test/ash-arith/arith-bash1.tests | |||
@@ -0,0 +1,5 @@ | |||
1 | # checks for [[ ]] | ||
2 | |||
3 | # && and || | ||
4 | [[ a && "" ]]; echo $? | ||
5 | [[ a || "" ]]; echo $? | ||
diff --git a/shell/ash_test/ash-vars/var_bash1.right b/shell/ash_test/ash-vars/var_bash1.right new file mode 100644 index 000000000..c0a07699b --- /dev/null +++ b/shell/ash_test/ash-vars/var_bash1.right | |||
@@ -0,0 +1,14 @@ | |||
1 | |||
2 | |||
3 | f | ||
4 | bcdef | ||
5 | abcdef | ||
6 | abcdef | ||
7 | bcde | ||
8 | abcd | ||
9 | abcd | ||
10 | abcdef | ||
11 | bcdef | ||
12 | abcdef | ||
13 | abcdef | ||
14 | abcdef | ||
diff --git a/shell/ash_test/ash-vars/var_bash1.tests b/shell/ash_test/ash-vars/var_bash1.tests new file mode 100755 index 000000000..24d3c9a00 --- /dev/null +++ b/shell/ash_test/ash-vars/var_bash1.tests | |||
@@ -0,0 +1,18 @@ | |||
1 | var=abcdef | ||
2 | |||
3 | echo ${var:7} | ||
4 | echo ${var:6} | ||
5 | echo ${var:5} | ||
6 | echo ${var:1} | ||
7 | echo ${var:0} | ||
8 | echo ${var:-1} | ||
9 | |||
10 | echo ${var:1:4} | ||
11 | echo ${var:0:4} | ||
12 | echo ${var::4} | ||
13 | echo ${var:-1:4} | ||
14 | |||
15 | echo ${var:1:7} | ||
16 | echo ${var:0:7} | ||
17 | echo ${var::7} | ||
18 | echo ${var:-1:7} | ||
diff --git a/shell/ash_test/ash-vars/var_bash2.right b/shell/ash_test/ash-vars/var_bash2.right new file mode 100644 index 000000000..acba5c6fb --- /dev/null +++ b/shell/ash_test/ash-vars/var_bash2.right | |||
@@ -0,0 +1,10 @@ | |||
1 | abc123xcba123 | ||
2 | abx123dcba123 | ||
3 | abx123dxba123 | ||
4 | abcx23dcba123 | ||
5 | abcxxxdcbaxxx | ||
6 | abx | ||
7 | xba123 | ||
8 | abx23 | ||
9 | abc23dcba123 | ||
10 | abcdcba | ||
diff --git a/shell/ash_test/ash-vars/var_bash2.tests b/shell/ash_test/ash-vars/var_bash2.tests new file mode 100755 index 000000000..29c526cef --- /dev/null +++ b/shell/ash_test/ash-vars/var_bash2.tests | |||
@@ -0,0 +1,24 @@ | |||
1 | var=abc123dcba123 | ||
2 | |||
3 | echo ${var/d/x} | ||
4 | echo ${var/c/x} | ||
5 | echo ${var//c/x} | ||
6 | echo ${var/[123]/x} | ||
7 | echo ${var//[123]/x} | ||
8 | echo ${var/c*/x} | ||
9 | echo ${var/*c/x} | ||
10 | |||
11 | # must match longest match: result is "abx23" | ||
12 | echo ${var/c*1/x} | ||
13 | |||
14 | # empty replacement - 2nd slash can be omitted | ||
15 | echo ${var/[123]} | ||
16 | echo ${var//[123]} | ||
17 | |||
18 | ### ash doesn't support | ||
19 | ### # match only at the beginning: | ||
20 | ### echo ${var/#a/x} | ||
21 | ### echo ${var/#b/x} # should not match | ||
22 | ### echo ${var//#b/x} # should not match | ||
23 | ### # match only at the end: | ||
24 | ### echo ${var/%3/x} | ||