aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-05-21 15:24:12 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-05-21 15:24:12 +0200
commit73e013fca7afd2edc9ba8530df77c8210a14700b (patch)
treecee35b3493f12565fd20100be1ea2da4a6a86baf
parenta88585a931c7e81d4d3d393127d8ad8c0fe73fb5 (diff)
downloadbusybox-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.c10
-rw-r--r--shell/hush_test/hush-vars/param_expand_bash_substring.right12
-rwxr-xr-xshell/hush_test/hush-vars/param_expand_bash_substring.tests12
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}
71:1 =|| 71:1 =||
81:1:2=|| 81:1:2=||
91::2 =|| 91::2 =||
101:1: =||
111:: =||
101 =|0123| 121 =|0123|
111:1 =|123| 131:1 =|123|
121:1:2=|12| 141:1:2=|12|
131::2 =|01| 151::2 =|01|
161:1: =||
171:: =||
14f =|| 18f =||
15f:1 =|| 19f:1 =||
16f:1:2=|| 20f:1:2=||
17f::2 =|| 21f::2 =||
22f:1: =||
23f:: =||
18f =|| 24f =||
19f:1 =|| 25f:1 =||
20f:1:2=|| 26f:1:2=||
21f::2 =|| 27f::2 =||
28f:1: =||
29f:: =||
22f =|a| 30f =|a|
23f:1 =|| 31f:1 =||
24f:1:2=|| 32f:1:2=||
25f::2 =|a| 33f::2 =|a|
34f:1: =||
35f:: =||
26f =|0123456789| 36f =|0123456789|
27f:1 =|123456789| 37f:1 =|123456789|
28f:1:2=|12| 38f:1:2=|12|
29f::2 =|01| 39f::2 =|01|
40f:1: =||
41f:: =||
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::}|"'