diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-21 15:24:12 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-21 15:24:12 +0200 |
commit | 73e013fca7afd2edc9ba8530df77c8210a14700b (patch) | |
tree | cee35b3493f12565fd20100be1ea2da4a6a86baf | |
parent | a88585a931c7e81d4d3d393127d8ad8c0fe73fb5 (diff) | |
download | busybox-w32-73e013fca7afd2edc9ba8530df77c8210a14700b.tar.gz busybox-w32-73e013fca7afd2edc9ba8530df77c8210a14700b.tar.bz2 busybox-w32-73e013fca7afd2edc9ba8530df77c8210a14700b.zip |
hush: handle ${var:NUM:} too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 10 | ||||
-rw-r--r-- | shell/hush_test/hush-vars/param_expand_bash_substring.right | 12 | ||||
-rwxr-xr-x | shell/hush_test/hush-vars/param_expand_bash_substring.tests | 12 |
3 files changed, 32 insertions, 2 deletions
diff --git a/shell/hush.c b/shell/hush.c index 945077d87..6cf8899b0 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -2649,12 +2649,17 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg, char | |||
2649 | beg = bb_strtou(exp_word, &end, 0); | 2649 | beg = bb_strtou(exp_word, &end, 0); |
2650 | //bb_error_msg("beg:'%s'=%u end:'%s'", exp_word, beg, end); | 2650 | //bb_error_msg("beg:'%s'=%u end:'%s'", exp_word, beg, end); |
2651 | if (*end == ':') { | 2651 | if (*end == ':') { |
2652 | len = bb_strtou(end + 1, &end, 0); | 2652 | if (end[1] != '\0') /* not ${var:NUM:} */ |
2653 | len = bb_strtou(end + 1, &end, 0); | ||
2654 | else { | ||
2655 | len = 0; | ||
2656 | end++; | ||
2657 | } | ||
2653 | //bb_error_msg("len:%u end:'%s'", len, end); | 2658 | //bb_error_msg("len:%u end:'%s'", len, end); |
2654 | } | 2659 | } |
2655 | if (*end == '\0') { | 2660 | if (*end == '\0') { |
2656 | //bb_error_msg("from val:'%s'", val); | 2661 | //bb_error_msg("from val:'%s'", val); |
2657 | if (!val || beg >= strlen(val)) | 2662 | if (len == 0 || !val || beg >= strlen(val)) |
2658 | val = ""; | 2663 | val = ""; |
2659 | else | 2664 | else |
2660 | val = dyn_val = xstrndup(val + beg, len); | 2665 | val = dyn_val = xstrndup(val + beg, len); |
@@ -2663,6 +2668,7 @@ static NOINLINE int expand_vars_to_list(o_string *output, int n, char *arg, char | |||
2663 | #endif | 2668 | #endif |
2664 | { | 2669 | { |
2665 | die_if_script("malformed ${%s...}", var); | 2670 | die_if_script("malformed ${%s...}", var); |
2671 | val = ""; | ||
2666 | } | 2672 | } |
2667 | } else { /* one of "-=+?" */ | 2673 | } else { /* one of "-=+?" */ |
2668 | /* Standard-mandated substitution ops: | 2674 | /* Standard-mandated substitution ops: |
diff --git a/shell/hush_test/hush-vars/param_expand_bash_substring.right b/shell/hush_test/hush-vars/param_expand_bash_substring.right index 9cd465938..6e3eb3ba6 100644 --- a/shell/hush_test/hush-vars/param_expand_bash_substring.right +++ b/shell/hush_test/hush-vars/param_expand_bash_substring.right | |||
@@ -7,23 +7,35 @@ hush: syntax error: unterminated ${name} | |||
7 | 1:1 =|| | 7 | 1:1 =|| |
8 | 1:1:2=|| | 8 | 1:1:2=|| |
9 | 1::2 =|| | 9 | 1::2 =|| |
10 | 1:1: =|| | ||
11 | 1:: =|| | ||
10 | 1 =|0123| | 12 | 1 =|0123| |
11 | 1:1 =|123| | 13 | 1:1 =|123| |
12 | 1:1:2=|12| | 14 | 1:1:2=|12| |
13 | 1::2 =|01| | 15 | 1::2 =|01| |
16 | 1:1: =|| | ||
17 | 1:: =|| | ||
14 | f =|| | 18 | f =|| |
15 | f:1 =|| | 19 | f:1 =|| |
16 | f:1:2=|| | 20 | f:1:2=|| |
17 | f::2 =|| | 21 | f::2 =|| |
22 | f:1: =|| | ||
23 | f:: =|| | ||
18 | f =|| | 24 | f =|| |
19 | f:1 =|| | 25 | f:1 =|| |
20 | f:1:2=|| | 26 | f:1:2=|| |
21 | f::2 =|| | 27 | f::2 =|| |
28 | f:1: =|| | ||
29 | f:: =|| | ||
22 | f =|a| | 30 | f =|a| |
23 | f:1 =|| | 31 | f:1 =|| |
24 | f:1:2=|| | 32 | f:1:2=|| |
25 | f::2 =|a| | 33 | f::2 =|a| |
34 | f:1: =|| | ||
35 | f:: =|| | ||
26 | f =|0123456789| | 36 | f =|0123456789| |
27 | f:1 =|123456789| | 37 | f:1 =|123456789| |
28 | f:1:2=|12| | 38 | f:1:2=|12| |
29 | f::2 =|01| | 39 | f::2 =|01| |
40 | f:1: =|| | ||
41 | f:: =|| | ||
diff --git a/shell/hush_test/hush-vars/param_expand_bash_substring.tests b/shell/hush_test/hush-vars/param_expand_bash_substring.tests index 6a1765559..eedd435ed 100755 --- a/shell/hush_test/hush-vars/param_expand_bash_substring.tests +++ b/shell/hush_test/hush-vars/param_expand_bash_substring.tests | |||
@@ -19,28 +19,40 @@ export var=0123456789 | |||
19 | "$THIS_SH" -c 'set --; echo "1:1 =|${1:1}|"' | 19 | "$THIS_SH" -c 'set --; echo "1:1 =|${1:1}|"' |
20 | "$THIS_SH" -c 'set --; echo "1:1:2=|${1:1:2}|"' | 20 | "$THIS_SH" -c 'set --; echo "1:1:2=|${1:1:2}|"' |
21 | "$THIS_SH" -c 'set --; echo "1::2 =|${1::2}|"' | 21 | "$THIS_SH" -c 'set --; echo "1::2 =|${1::2}|"' |
22 | "$THIS_SH" -c 'set --; echo "1:1: =|${1:1:}|"' | ||
23 | "$THIS_SH" -c 'set --; echo "1:: =|${1::}|"' | ||
22 | 24 | ||
23 | "$THIS_SH" -c 'set -- 0123; echo "1 =|${1}|"' | 25 | "$THIS_SH" -c 'set -- 0123; echo "1 =|${1}|"' |
24 | "$THIS_SH" -c 'set -- 0123; echo "1:1 =|${1:1}|"' | 26 | "$THIS_SH" -c 'set -- 0123; echo "1:1 =|${1:1}|"' |
25 | "$THIS_SH" -c 'set -- 0123; echo "1:1:2=|${1:1:2}|"' | 27 | "$THIS_SH" -c 'set -- 0123; echo "1:1:2=|${1:1:2}|"' |
26 | "$THIS_SH" -c 'set -- 0123; echo "1::2 =|${1::2}|"' | 28 | "$THIS_SH" -c 'set -- 0123; echo "1::2 =|${1::2}|"' |
29 | "$THIS_SH" -c 'set -- 0123; echo "1:1: =|${1:1:}|"' | ||
30 | "$THIS_SH" -c 'set -- 0123; echo "1:: =|${1::}|"' | ||
27 | 31 | ||
28 | "$THIS_SH" -c 'unset f; echo "f =|$f|"' | 32 | "$THIS_SH" -c 'unset f; echo "f =|$f|"' |
29 | "$THIS_SH" -c 'unset f; echo "f:1 =|${f:1}|"' | 33 | "$THIS_SH" -c 'unset f; echo "f:1 =|${f:1}|"' |
30 | "$THIS_SH" -c 'unset f; echo "f:1:2=|${f:1:2}|"' | 34 | "$THIS_SH" -c 'unset f; echo "f:1:2=|${f:1:2}|"' |
31 | "$THIS_SH" -c 'unset f; echo "f::2 =|${f::2}|"' | 35 | "$THIS_SH" -c 'unset f; echo "f::2 =|${f::2}|"' |
36 | "$THIS_SH" -c 'unset f; echo "f:1: =|${f:1:}|"' | ||
37 | "$THIS_SH" -c 'unset f; echo "f:: =|${f::}|"' | ||
32 | 38 | ||
33 | "$THIS_SH" -c 'f=; echo "f =|$f|"' | 39 | "$THIS_SH" -c 'f=; echo "f =|$f|"' |
34 | "$THIS_SH" -c 'f=; echo "f:1 =|${f:1}|"' | 40 | "$THIS_SH" -c 'f=; echo "f:1 =|${f:1}|"' |
35 | "$THIS_SH" -c 'f=; echo "f:1:2=|${f:1:2}|"' | 41 | "$THIS_SH" -c 'f=; echo "f:1:2=|${f:1:2}|"' |
36 | "$THIS_SH" -c 'f=; echo "f::2 =|${f::2}|"' | 42 | "$THIS_SH" -c 'f=; echo "f::2 =|${f::2}|"' |
43 | "$THIS_SH" -c 'f=; echo "f:1: =|${f:1:}|"' | ||
44 | "$THIS_SH" -c 'f=; echo "f:: =|${f::}|"' | ||
37 | 45 | ||
38 | "$THIS_SH" -c 'f=a; echo "f =|$f|"' | 46 | "$THIS_SH" -c 'f=a; echo "f =|$f|"' |
39 | "$THIS_SH" -c 'f=a; echo "f:1 =|${f:1}|"' | 47 | "$THIS_SH" -c 'f=a; echo "f:1 =|${f:1}|"' |
40 | "$THIS_SH" -c 'f=a; echo "f:1:2=|${f:1:2}|"' | 48 | "$THIS_SH" -c 'f=a; echo "f:1:2=|${f:1:2}|"' |
41 | "$THIS_SH" -c 'f=a; echo "f::2 =|${f::2}|"' | 49 | "$THIS_SH" -c 'f=a; echo "f::2 =|${f::2}|"' |
50 | "$THIS_SH" -c 'f=a; echo "f:1: =|${f:1:}|"' | ||
51 | "$THIS_SH" -c 'f=a; echo "f:: =|${f::}|"' | ||
42 | 52 | ||
43 | "$THIS_SH" -c 'f=0123456789; echo "f =|$f|"' | 53 | "$THIS_SH" -c 'f=0123456789; echo "f =|$f|"' |
44 | "$THIS_SH" -c 'f=0123456789; echo "f:1 =|${f:1}|"' | 54 | "$THIS_SH" -c 'f=0123456789; echo "f:1 =|${f:1}|"' |
45 | "$THIS_SH" -c 'f=0123456789; echo "f:1:2=|${f:1:2}|"' | 55 | "$THIS_SH" -c 'f=0123456789; echo "f:1:2=|${f:1:2}|"' |
46 | "$THIS_SH" -c 'f=0123456789; echo "f::2 =|${f::2}|"' | 56 | "$THIS_SH" -c 'f=0123456789; echo "f::2 =|${f::2}|"' |
57 | "$THIS_SH" -c 'f=0123456789; echo "f:1: =|${f:1:}|"' | ||
58 | "$THIS_SH" -c 'f=0123456789; echo "f:: =|${f::}|"' | ||