diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-25 15:18:57 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-25 15:18:57 +0200 |
commit | 645c697372b714f1293a37a185aa62965f600479 (patch) | |
tree | 5033362b96737f83526b776818bf4c9a4ef8a9ef /shell | |
parent | 64925384c9cf5e0d986e183577da286bb3207ce7 (diff) | |
download | busybox-w32-645c697372b714f1293a37a185aa62965f600479.tar.gz busybox-w32-645c697372b714f1293a37a185aa62965f600479.tar.bz2 busybox-w32-645c697372b714f1293a37a185aa62965f600479.zip |
hush: treat ${#?} as "length of $?"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r-- | shell/ash_test/ash-vars/param_expand_indicate_error.right | 43 | ||||
-rwxr-xr-x | shell/ash_test/ash-vars/param_expand_indicate_error.tests | 61 | ||||
-rw-r--r-- | shell/hush.c | 12 | ||||
-rw-r--r-- | shell/hush_test/hush-vars/param_expand_indicate_error.right | 2 | ||||
-rwxr-xr-x | shell/hush_test/hush-vars/param_expand_indicate_error.tests | 2 |
5 files changed, 115 insertions, 5 deletions
diff --git a/shell/ash_test/ash-vars/param_expand_indicate_error.right b/shell/ash_test/ash-vars/param_expand_indicate_error.right new file mode 100644 index 000000000..33afacee0 --- /dev/null +++ b/shell/ash_test/ash-vars/param_expand_indicate_error.right | |||
@@ -0,0 +1,43 @@ | |||
1 | SHELL: line 1: syntax error: bad substitution | ||
2 | 1 | ||
3 | 0 | ||
4 | ==== | ||
5 | _ | ||
6 | SHELL: line 1: 1: parameter not set | ||
7 | SHELL: line 1: 1: parameter not set or null | ||
8 | SHELL: line 1: 1: message1 | ||
9 | SHELL: line 1: 1: message1 | ||
10 | SHELL: line 1: 1: unset! | ||
11 | SHELL: line 1: 1: null or unset! | ||
12 | ==== | ||
13 | _aaaa | ||
14 | _aaaa | ||
15 | _aaaa | ||
16 | _aaaa | ||
17 | _aaaa | ||
18 | _aaaa | ||
19 | _aaaa | ||
20 | ==== | ||
21 | _ | ||
22 | SHELL: line 1: f: parameter not set | ||
23 | SHELL: line 1: f: parameter not set or null | ||
24 | SHELL: line 1: f: message3 | ||
25 | SHELL: line 1: f: message3 | ||
26 | SHELL: line 1: f: unset! | ||
27 | SHELL: line 1: f: null or unset! | ||
28 | ==== | ||
29 | _ | ||
30 | _ | ||
31 | SHELL: line 1: f: parameter not set or null | ||
32 | _ | ||
33 | SHELL: line 1: f: message4 | ||
34 | _ | ||
35 | SHELL: line 1: f: null or unset! | ||
36 | ==== | ||
37 | _fff | ||
38 | _fff | ||
39 | _fff | ||
40 | _fff | ||
41 | _fff | ||
42 | _fff | ||
43 | _fff | ||
diff --git a/shell/ash_test/ash-vars/param_expand_indicate_error.tests b/shell/ash_test/ash-vars/param_expand_indicate_error.tests new file mode 100755 index 000000000..0f3061949 --- /dev/null +++ b/shell/ash_test/ash-vars/param_expand_indicate_error.tests | |||
@@ -0,0 +1,61 @@ | |||
1 | # do all of these in subshells since it's supposed to error out | ||
2 | # (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages) | ||
3 | |||
4 | # first try some invalid patterns | ||
5 | #"$THIS_SH" -c 'echo ${?}' SHELL -- this is valid as it's the same as $? | ||
6 | "$THIS_SH" -c 'echo ${:?}' SHELL | ||
7 | |||
8 | # then some funky ones | ||
9 | # note: bash prints 1 - treats it as "length of $#" | ||
10 | "$THIS_SH" -c 'echo ${#?}' SHELL | ||
11 | # bash prints 0 | ||
12 | "$THIS_SH" -c 'echo ${#:?}' SHELL | ||
13 | |||
14 | # now some valid ones | ||
15 | export msg_unset="unset!" | ||
16 | export msg_null_or_unset="null or unset!" | ||
17 | |||
18 | echo ==== | ||
19 | "$THIS_SH" -c 'set --; echo _$1' SHELL | ||
20 | "$THIS_SH" -c 'set --; echo _${1?}' SHELL | ||
21 | "$THIS_SH" -c 'set --; echo _${1:?}' SHELL | ||
22 | "$THIS_SH" -c 'set --; echo _${1?message1}' SHELL | ||
23 | "$THIS_SH" -c 'set --; echo _${1:?message1}' SHELL | ||
24 | "$THIS_SH" -c 'set --; echo _${1?$msg_unset}' SHELL | ||
25 | "$THIS_SH" -c 'set --; echo _${1:?$msg_null_or_unset}' SHELL | ||
26 | |||
27 | echo ==== | ||
28 | "$THIS_SH" -c 'set -- aaaa; echo _$1' SHELL | ||
29 | "$THIS_SH" -c 'set -- aaaa; echo _${1?}' SHELL | ||
30 | "$THIS_SH" -c 'set -- aaaa; echo _${1:?}' SHELL | ||
31 | "$THIS_SH" -c 'set -- aaaa; echo _${1?word}' SHELL | ||
32 | "$THIS_SH" -c 'set -- aaaa; echo _${1:?word}' SHELL | ||
33 | "$THIS_SH" -c 'set -- aaaa; echo _${1?$msg_unset}' SHELL | ||
34 | "$THIS_SH" -c 'set -- aaaa; echo _${1:?$msg_null_or_unset}' SHELL | ||
35 | |||
36 | echo ==== | ||
37 | "$THIS_SH" -c 'unset f; echo _$f' SHELL | ||
38 | "$THIS_SH" -c 'unset f; echo _${f?}' SHELL | ||
39 | "$THIS_SH" -c 'unset f; echo _${f:?}' SHELL | ||
40 | "$THIS_SH" -c 'unset f; echo _${f?message3}' SHELL | ||
41 | "$THIS_SH" -c 'unset f; echo _${f:?message3}' SHELL | ||
42 | "$THIS_SH" -c 'unset f; echo _${f?$msg_unset}' SHELL | ||
43 | "$THIS_SH" -c 'unset f; echo _${f:?$msg_null_or_unset}' SHELL | ||
44 | |||
45 | echo ==== | ||
46 | "$THIS_SH" -c 'f=; echo _$f' SHELL | ||
47 | "$THIS_SH" -c 'f=; echo _${f?}' SHELL | ||
48 | "$THIS_SH" -c 'f=; echo _${f:?}' SHELL | ||
49 | "$THIS_SH" -c 'f=; echo _${f?word}' SHELL | ||
50 | "$THIS_SH" -c 'f=; echo _${f:?message4}' SHELL | ||
51 | "$THIS_SH" -c 'f=; echo _${f?$msg_unset}' SHELL | ||
52 | "$THIS_SH" -c 'f=; echo _${f:?$msg_null_or_unset}' SHELL | ||
53 | |||
54 | echo ==== | ||
55 | "$THIS_SH" -c 'f=fff; echo _$f' SHELL | ||
56 | "$THIS_SH" -c 'f=fff; echo _${f?}' SHELL | ||
57 | "$THIS_SH" -c 'f=fff; echo _${f:?}' SHELL | ||
58 | "$THIS_SH" -c 'f=fff; echo _${f?word}' SHELL | ||
59 | "$THIS_SH" -c 'f=fff; echo _${f:?word}' SHELL | ||
60 | "$THIS_SH" -c 'f=fff; echo _${f?$msg_unset}' SHELL | ||
61 | "$THIS_SH" -c 'f=fff; echo _${f:?$msg_null_or_unset}' SHELL | ||
diff --git a/shell/hush.c b/shell/hush.c index 20b092398..f9dad074f 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -5559,8 +5559,10 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha | |||
5559 | first_char = arg[0] = arg0 & 0x7f; | 5559 | first_char = arg[0] = arg0 & 0x7f; |
5560 | exp_op = 0; | 5560 | exp_op = 0; |
5561 | 5561 | ||
5562 | if (first_char == '#' /* ${#... */ | 5562 | if (first_char == '#' && arg[1] /* ${#... but not ${#} */ |
5563 | && arg[1] && !exp_saveptr /* not ${#} and not ${#<op_char>...} */ | 5563 | && (!exp_saveptr /* and (not ${#<op_char>...} */ |
5564 | || (arg[1] == '?' && arg[2] == '\0') /* or ${#?} - "len of $?") */ | ||
5565 | ) | ||
5564 | ) { | 5566 | ) { |
5565 | /* It must be length operator: ${#var} */ | 5567 | /* It must be length operator: ${#var} */ |
5566 | var++; | 5568 | var++; |
@@ -5797,7 +5799,11 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha | |||
5797 | /* mimic bash message */ | 5799 | /* mimic bash message */ |
5798 | die_if_script("%s: %s", | 5800 | die_if_script("%s: %s", |
5799 | var, | 5801 | var, |
5800 | exp_word[0] ? exp_word : "parameter null or not set" | 5802 | exp_word[0] |
5803 | ? exp_word | ||
5804 | : "parameter null or not set" | ||
5805 | /* ash has more specific messages, a-la: */ | ||
5806 | /*: (exp_save == ':' ? "parameter null or not set" : "parameter not set")*/ | ||
5801 | ); | 5807 | ); |
5802 | //TODO: how interactive bash aborts expansion mid-command? | 5808 | //TODO: how interactive bash aborts expansion mid-command? |
5803 | } else { | 5809 | } else { |
diff --git a/shell/hush_test/hush-vars/param_expand_indicate_error.right b/shell/hush_test/hush-vars/param_expand_indicate_error.right index 06fcc5104..acf293893 100644 --- a/shell/hush_test/hush-vars/param_expand_indicate_error.right +++ b/shell/hush_test/hush-vars/param_expand_indicate_error.right | |||
@@ -1,5 +1,5 @@ | |||
1 | hush: syntax error: unterminated ${name} | 1 | hush: syntax error: unterminated ${name} |
2 | 0 | 2 | 1 |
3 | 0 | 3 | 0 |
4 | ==== | 4 | ==== |
5 | _ | 5 | _ |
diff --git a/shell/hush_test/hush-vars/param_expand_indicate_error.tests b/shell/hush_test/hush-vars/param_expand_indicate_error.tests index be14b1e37..5f946e39a 100755 --- a/shell/hush_test/hush-vars/param_expand_indicate_error.tests +++ b/shell/hush_test/hush-vars/param_expand_indicate_error.tests | |||
@@ -5,7 +5,7 @@ | |||
5 | "$THIS_SH" -c 'echo ${:?}' | 5 | "$THIS_SH" -c 'echo ${:?}' |
6 | 6 | ||
7 | # then some funky ones | 7 | # then some funky ones |
8 | # note: bash prints 1 - treats it as "length of $#"? We print 0 | 8 | # note: bash prints 1 - treats it as "length of $#" |
9 | "$THIS_SH" -c 'echo ${#?}' | 9 | "$THIS_SH" -c 'echo ${#?}' |
10 | # bash prints 0 | 10 | # bash prints 0 |
11 | "$THIS_SH" -c 'echo ${#:?}' | 11 | "$THIS_SH" -c 'echo ${#:?}' |