diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-22 03:12:29 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-22 03:12:29 +0200 |
commit | 1e811b12317d0eab4e78d848caa640cca497a0a7 (patch) | |
tree | ef60262af7944dfe557542bec9e1fb8bea367b60 /shell/hush_test/hush-vars | |
parent | ddc62f64baad8abdeb587b13afe8d47fb347981c (diff) | |
download | busybox-1e811b12317d0eab4e78d848caa640cca497a0a7.tar.gz |
hush: support ${var:EXPR:EXPR}!
function old new delta
handle_dollar 574 681 +107
expand_and_evaluate_arith - 77 +77
expand_vars_to_list 2302 2374 +72
add_till_closing_bracket 359 368 +9
builtin_exit 48 47 -1
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/1 up/down: 265/-1) Total: 264 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush_test/hush-vars')
-rw-r--r-- | shell/hush_test/hush-vars/param_expand_bash_substring.right | 10 | ||||
-rwxr-xr-x | shell/hush_test/hush-vars/param_expand_bash_substring.tests | 98 |
2 files changed, 64 insertions, 44 deletions
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 6e3eb3ba6..53b8836ff 100644 --- a/shell/hush_test/hush-vars/param_expand_bash_substring.right +++ b/shell/hush_test/hush-vars/param_expand_bash_substring.right @@ -39,3 +39,13 @@ f:1:2=|12| f::2 =|01| f:1: =|| f:: =|| +Substrings with expressions +f =|01234567| +f:1+1:2+2 =|2345| +f:-1:2+2 =|01234567| +f:1:f =|1234567| +f:1:$f =|1234567| +f:1:${f} =|1234567| +f:1:${f:3:1} =|123| +f:1:1`echo 1`=|1| +Done 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 eedd435ed..a80523add 100755 --- a/shell/hush_test/hush-vars/param_expand_bash_substring.tests +++ b/shell/hush_test/hush-vars/param_expand_bash_substring.tests @@ -1,8 +1,6 @@ +# first try some invalid patterns # do all of these in subshells since it's supposed to error out - export var=0123456789 - -# first try some invalid patterns "$THIS_SH" -c 'echo ${:}' "$THIS_SH" -c 'echo ${::}' "$THIS_SH" -c 'echo ${:1}' @@ -15,44 +13,56 @@ export var=0123456789 # UNFIXED BUG: this should work: "$THIS_SH" -c 'echo ${?:0}' # now some valid ones -"$THIS_SH" -c 'set --; echo "1 =|${1}|"' -"$THIS_SH" -c 'set --; echo "1:1 =|${1:1}|"' -"$THIS_SH" -c 'set --; echo "1:1:2=|${1:1:2}|"' -"$THIS_SH" -c 'set --; echo "1::2 =|${1::2}|"' -"$THIS_SH" -c 'set --; echo "1:1: =|${1:1:}|"' -"$THIS_SH" -c 'set --; echo "1:: =|${1::}|"' - -"$THIS_SH" -c 'set -- 0123; echo "1 =|${1}|"' -"$THIS_SH" -c 'set -- 0123; echo "1:1 =|${1:1}|"' -"$THIS_SH" -c 'set -- 0123; echo "1:1:2=|${1:1:2}|"' -"$THIS_SH" -c 'set -- 0123; echo "1::2 =|${1::2}|"' -"$THIS_SH" -c 'set -- 0123; echo "1:1: =|${1:1:}|"' -"$THIS_SH" -c 'set -- 0123; echo "1:: =|${1::}|"' - -"$THIS_SH" -c 'unset f; echo "f =|$f|"' -"$THIS_SH" -c 'unset f; echo "f:1 =|${f:1}|"' -"$THIS_SH" -c 'unset f; echo "f:1:2=|${f:1:2}|"' -"$THIS_SH" -c 'unset f; echo "f::2 =|${f::2}|"' -"$THIS_SH" -c 'unset f; echo "f:1: =|${f:1:}|"' -"$THIS_SH" -c 'unset f; echo "f:: =|${f::}|"' - -"$THIS_SH" -c 'f=; echo "f =|$f|"' -"$THIS_SH" -c 'f=; echo "f:1 =|${f:1}|"' -"$THIS_SH" -c 'f=; echo "f:1:2=|${f:1:2}|"' -"$THIS_SH" -c 'f=; echo "f::2 =|${f::2}|"' -"$THIS_SH" -c 'f=; echo "f:1: =|${f:1:}|"' -"$THIS_SH" -c 'f=; echo "f:: =|${f::}|"' - -"$THIS_SH" -c 'f=a; echo "f =|$f|"' -"$THIS_SH" -c 'f=a; echo "f:1 =|${f:1}|"' -"$THIS_SH" -c 'f=a; echo "f:1:2=|${f:1:2}|"' -"$THIS_SH" -c 'f=a; echo "f::2 =|${f::2}|"' -"$THIS_SH" -c 'f=a; echo "f:1: =|${f:1:}|"' -"$THIS_SH" -c 'f=a; echo "f:: =|${f::}|"' - -"$THIS_SH" -c 'f=0123456789; echo "f =|$f|"' -"$THIS_SH" -c 'f=0123456789; echo "f:1 =|${f:1}|"' -"$THIS_SH" -c 'f=0123456789; echo "f:1:2=|${f:1:2}|"' -"$THIS_SH" -c 'f=0123456789; echo "f::2 =|${f::2}|"' -"$THIS_SH" -c 'f=0123456789; echo "f:1: =|${f:1:}|"' -"$THIS_SH" -c 'f=0123456789; echo "f:: =|${f::}|"' +set --; echo "1 =|${1}|" +set --; echo "1:1 =|${1:1}|" +set --; echo "1:1:2=|${1:1:2}|" +set --; echo "1::2 =|${1::2}|" +set --; echo "1:1: =|${1:1:}|" +set --; echo "1:: =|${1::}|" + +set -- 0123; echo "1 =|${1}|" +set -- 0123; echo "1:1 =|${1:1}|" +set -- 0123; echo "1:1:2=|${1:1:2}|" +set -- 0123; echo "1::2 =|${1::2}|" +set -- 0123; echo "1:1: =|${1:1:}|" +set -- 0123; echo "1:: =|${1::}|" + +unset f; echo "f =|$f|" +unset f; echo "f:1 =|${f:1}|" +unset f; echo "f:1:2=|${f:1:2}|" +unset f; echo "f::2 =|${f::2}|" +unset f; echo "f:1: =|${f:1:}|" +unset f; echo "f:: =|${f::}|" + +f=; echo "f =|$f|" +f=; echo "f:1 =|${f:1}|" +f=; echo "f:1:2=|${f:1:2}|" +f=; echo "f::2 =|${f::2}|" +f=; echo "f:1: =|${f:1:}|" +f=; echo "f:: =|${f::}|" + +f=a; echo "f =|$f|" +f=a; echo "f:1 =|${f:1}|" +f=a; echo "f:1:2=|${f:1:2}|" +f=a; echo "f::2 =|${f::2}|" +f=a; echo "f:1: =|${f:1:}|" +f=a; echo "f:: =|${f::}|" + +f=0123456789; echo "f =|$f|" +f=0123456789; echo "f:1 =|${f:1}|" +f=0123456789; echo "f:1:2=|${f:1:2}|" +f=0123456789; echo "f::2 =|${f::2}|" +f=0123456789; echo "f:1: =|${f:1:}|" +f=0123456789; echo "f:: =|${f::}|" + +echo "Substrings with expressions" +f=01234567; echo 'f '"=|$f|" +f=01234567; echo 'f:1+1:2+2 '"=|${f:1+1:2+2}|" +f=01234567; echo 'f:-1:2+2 '"=|${f:-1:2+2}|" +f=01234567; echo 'f:1:f '"=|${f:1:f}|" +f=01234567; echo 'f:1:$f '"=|${f:1:$f}|" +f=01234567; echo 'f:1:${f} '"=|${f:1:${f}}|" +f=01234567; echo 'f:1:${f:3:1} '"=|${f:1:${f:3:1}}|" +f=01234567; echo 'f:1:1`echo 1`'"=|${f:1:`echo 1`}|" + +echo Done |