diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-26 00:07:27 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-07-26 00:07:27 +0200 |
commit | 2093ad296f8a4528ad0e106b52074871a2bf070e (patch) | |
tree | d94c965340ab56f3394b4c3fba675df29ed43f80 /shell/hush_test | |
parent | 1e3e2ccd5dd280371c9ca29c0e0304a0d40592af (diff) | |
download | busybox-w32-2093ad296f8a4528ad0e106b52074871a2bf070e.tar.gz busybox-w32-2093ad296f8a4528ad0e106b52074871a2bf070e.tar.bz2 busybox-w32-2093ad296f8a4528ad0e106b52074871a2bf070e.zip |
hush: fix ${##}, ${#?}, ${#!} handling
function old new delta
parse_dollar 786 820 +34
expand_one_var 1579 1592 +13
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 47/0) Total: 47 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush_test')
-rwxr-xr-x | shell/hush_test/hush-vars/param_expand_alt.tests | 2 | ||||
-rw-r--r-- | shell/hush_test/hush-vars/param_expand_len1.right | 11 | ||||
-rwxr-xr-x | shell/hush_test/hush-vars/param_expand_len1.tests | 31 |
3 files changed, 43 insertions, 1 deletions
diff --git a/shell/hush_test/hush-vars/param_expand_alt.tests b/shell/hush_test/hush-vars/param_expand_alt.tests index c9c4249af..d80452434 100755 --- a/shell/hush_test/hush-vars/param_expand_alt.tests +++ b/shell/hush_test/hush-vars/param_expand_alt.tests | |||
@@ -6,7 +6,7 @@ | |||
6 | # now some funky ones. | 6 | # now some funky ones. |
7 | # ${V+word} "if V unset, then substitute nothing, else substitute word" | 7 | # ${V+word} "if V unset, then substitute nothing, else substitute word" |
8 | # ${V:+word} "if V unset or '', then substitute nothing, else substitute word" | 8 | # ${V:+word} "if V unset or '', then substitute nothing, else substitute word" |
9 | # bash doesn't accept ${#+}. ash prints 0 (not $#). | 9 | # bash doesn't accept ${#+}. ash prints 0 (not $#): "len of $+" |
10 | echo _${#+}_ _${#:+}_ | 10 | echo _${#+}_ _${#:+}_ |
11 | # Forms with non-empty word work as expected in both ash and bash. | 11 | # Forms with non-empty word work as expected in both ash and bash. |
12 | echo _${#+z}_ _${#:+z}_ | 12 | echo _${#+z}_ _${#:+z}_ |
diff --git a/shell/hush_test/hush-vars/param_expand_len1.right b/shell/hush_test/hush-vars/param_expand_len1.right new file mode 100644 index 000000000..dff3c7bb1 --- /dev/null +++ b/shell/hush_test/hush-vars/param_expand_len1.right | |||
@@ -0,0 +1,11 @@ | |||
1 | One:1 | ||
2 | Two:2 | ||
3 | Three:3 | ||
4 | |||
5 | One:1 | ||
6 | Two:2 | ||
7 | Three:3 | ||
8 | |||
9 | Ok ${#$}: 0 | ||
10 | |||
11 | Ok ${#!}: 0 | ||
diff --git a/shell/hush_test/hush-vars/param_expand_len1.tests b/shell/hush_test/hush-vars/param_expand_len1.tests new file mode 100755 index 000000000..e1beab320 --- /dev/null +++ b/shell/hush_test/hush-vars/param_expand_len1.tests | |||
@@ -0,0 +1,31 @@ | |||
1 | # ${#c} for any single char c means "length of $c", including all special vars | ||
2 | |||
3 | false | ||
4 | echo One:${#?} | ||
5 | (exit 10) | ||
6 | echo Two:${#?} | ||
7 | (exit 100) | ||
8 | echo Three:${#?} | ||
9 | |||
10 | echo | ||
11 | echo One:${##} | ||
12 | set -- 1 2 3 4 5 6 7 8 9 0 | ||
13 | echo Two:${##} | ||
14 | set -- 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 \ | ||
15 | 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 \ | ||
16 | 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 \ | ||
17 | 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 | ||
18 | echo Three:${##} | ||
19 | |||
20 | echo | ||
21 | v=$$ | ||
22 | test "${#v}" = "${#$}" | ||
23 | echo 'Ok ${#$}:' $? | ||
24 | |||
25 | echo | ||
26 | sleep 0 & | ||
27 | v=$! | ||
28 | test "${#v}" = "${#!}" | ||
29 | echo 'Ok ${#!}:' $? | ||
30 | |||
31 | # TODO: ${#-} ${#_} | ||