Start 1.33.0 development cycle
[oweals/busybox.git] / shell / hush_test / hush-vars / param_expand_bash_substring.tests
1 # first try some invalid patterns
2 # do all of these in subshells since it's supposed to error out
3 # (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages)
4 export var=0123456789
5 "$THIS_SH" -c 'echo ${:}' SHELL
6 "$THIS_SH" -c 'echo ${::}' SHELL
7 "$THIS_SH" -c 'echo ${:1}' SHELL
8 "$THIS_SH" -c 'echo ${::1}' SHELL
9
10 #this also is not valid in bash, hush accepts it:
11 "$THIS_SH" -c 'echo ${var:}' SHELL
12
13 # then some funky ones
14 "$THIS_SH" -c 'echo ${?:0}' SHELL
15
16 # now some valid ones
17 set --; echo "1    =|${1}|"
18 set --; echo "1:1  =|${1:1}|"
19 set --; echo "1:1:2=|${1:1:2}|"
20 set --; echo "1::2 =|${1::2}|"
21 set --; echo "1:1: =|${1:1:}|"
22 set --; echo "1::  =|${1::}|"
23
24 set -- 0123; echo "1    =|${1}|"
25 set -- 0123; echo "1:1  =|${1:1}|"
26 set -- 0123; echo "1:1:2=|${1:1:2}|"
27 set -- 0123; echo "1::2 =|${1::2}|"
28 set -- 0123; echo "1:1: =|${1:1:}|"
29 set -- 0123; echo "1::  =|${1::}|"
30
31 unset f; echo "f    =|$f|"
32 unset f; echo "f:1  =|${f:1}|"
33 unset f; echo "f:1:2=|${f:1:2}|"
34 unset f; echo "f::2 =|${f::2}|"
35 unset f; echo "f:1: =|${f:1:}|"
36 unset f; echo "f::  =|${f::}|"
37
38 f=; echo "f    =|$f|"
39 f=; echo "f:1  =|${f:1}|"
40 f=; echo "f:1:2=|${f:1:2}|"
41 f=; echo "f::2 =|${f::2}|"
42 f=; echo "f:1: =|${f:1:}|"
43 f=; echo "f::  =|${f::}|"
44
45 f=a; echo "f    =|$f|"
46 f=a; echo "f:1  =|${f:1}|"
47 f=a; echo "f:1:2=|${f:1:2}|"
48 f=a; echo "f::2 =|${f::2}|"
49 f=a; echo "f:1: =|${f:1:}|"
50 f=a; echo "f::  =|${f::}|"
51
52 f=0123456789; echo "f    =|$f|"
53 f=0123456789; echo "f:1  =|${f:1}|"
54 f=0123456789; echo "f:1:2=|${f:1:2}|"
55 f=0123456789; echo "f::2 =|${f::2}|"
56 f=0123456789; echo "f:1: =|${f:1:}|"
57 f=0123456789; echo "f::  =|${f::}|"
58
59 echo "Substrings from special vars"
60 echo '?    '"=|$?|"
61 echo '?:1  '"=|${?:1}|"
62 echo '?:1:2'"=|${?:1:2}|"
63 echo '?::2 '"=|${?::2}|"
64 echo '?:1: '"=|${?:1:}|"
65 echo '?::  '"=|${?::}|"
66 set -- 1 2 3 4 5 6 7 8 9 10 11
67 echo '#    '"=|$#|"
68 echo '#:1  '"=|${#:1}|"
69 echo '#:1:2'"=|${#:1:2}|"
70 echo '#::2 '"=|${#::2}|"
71 echo '#:1: '"=|${#:1:}|"
72 echo '#::  '"=|${#::}|"
73
74 echo "Substrings with expressions"
75 f=01234567; echo 'f            '"=|$f|"
76 f=01234567; echo 'f:1+1:2+2    '"=|${f:1+1:2+2}|"
77 f=01234567; echo 'f:-1:2+2     '"=|${f:-1:2+2}|"
78 f=01234567; echo 'f:1:f        '"=|${f:1:f}|"
79 f=01234567; echo 'f:1:$f       '"=|${f:1:$f}|"
80 f=01234567; echo 'f:1:${f}     '"=|${f:1:${f}}|"
81 f=01234567; echo 'f:1:${f:3:1} '"=|${f:1:${f:3:1}}|"
82 f=01234567; echo 'f:1:1`echo 1`'"=|${f:1:`echo 1`}|"
83
84 echo Done