5c9552dbabc13e01939142bfaf9159ca87bf9878
[external/busybox.git] / util-linux / 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 export var=0123456789
4 "$THIS_SH" -c 'echo ${:}'
5 "$THIS_SH" -c 'echo ${::}'
6 "$THIS_SH" -c 'echo ${:1}'
7 "$THIS_SH" -c 'echo ${::1}'
8
9 #this also is not valid in bash, but we accept it:
10 "$THIS_SH" -c 'echo ${var:}'
11
12 # then some funky ones
13 # UNFIXED BUG: this should work: "$THIS_SH" -c 'echo ${?:0}'
14
15 # now some valid ones
16 set --; echo "1    =|${1}|"
17 set --; echo "1:1  =|${1:1}|"
18 set --; echo "1:1:2=|${1:1:2}|"
19 set --; echo "1::2 =|${1::2}|"
20 set --; echo "1:1: =|${1:1:}|"
21 set --; echo "1::  =|${1::}|"
22
23 set -- 0123; echo "1    =|${1}|"
24 set -- 0123; echo "1:1  =|${1:1}|"
25 set -- 0123; echo "1:1:2=|${1:1:2}|"
26 set -- 0123; echo "1::2 =|${1::2}|"
27 set -- 0123; echo "1:1: =|${1:1:}|"
28 set -- 0123; echo "1::  =|${1::}|"
29
30 unset f; echo "f    =|$f|"
31 unset f; echo "f:1  =|${f:1}|"
32 unset f; echo "f:1:2=|${f:1:2}|"
33 unset f; echo "f::2 =|${f::2}|"
34 unset f; echo "f:1: =|${f:1:}|"
35 unset f; echo "f::  =|${f::}|"
36
37 f=; echo "f    =|$f|"
38 f=; echo "f:1  =|${f:1}|"
39 f=; echo "f:1:2=|${f:1:2}|"
40 f=; echo "f::2 =|${f::2}|"
41 f=; echo "f:1: =|${f:1:}|"
42 f=; echo "f::  =|${f::}|"
43
44 f=a; echo "f    =|$f|"
45 f=a; echo "f:1  =|${f:1}|"
46 f=a; echo "f:1:2=|${f:1:2}|"
47 f=a; echo "f::2 =|${f::2}|"
48 f=a; echo "f:1: =|${f:1:}|"
49 f=a; echo "f::  =|${f::}|"
50
51 f=0123456789; echo "f    =|$f|"
52 f=0123456789; echo "f:1  =|${f:1}|"
53 f=0123456789; echo "f:1:2=|${f:1:2}|"
54 f=0123456789; echo "f::2 =|${f::2}|"
55 f=0123456789; echo "f:1: =|${f:1:}|"
56 f=0123456789; echo "f::  =|${f::}|"
57
58 echo "Substrings from special vars"
59 echo '?    '"=|$?|"
60 echo '?:1  '"=|${?:1}|"
61 echo '?:1:2'"=|${?:1:2}|"
62 echo '?::2 '"=|${?::2}|"
63 echo '?:1: '"=|${?:1:}|"
64 echo '?::  '"=|${?::}|"
65 set -- 1 2 3 4 5 6 7 8 9 10 11
66 echo '#    '"=|$#|"
67 echo '#:1  '"=|${#:1}|"
68 echo '#:1:2'"=|${#:1:2}|"
69 echo '#::2 '"=|${#::2}|"
70 echo '#:1: '"=|${#:1:}|"
71 echo '#::  '"=|${#::}|"
72
73 echo "Substrings with expressions"
74 f=01234567; echo 'f            '"=|$f|"
75 f=01234567; echo 'f:1+1:2+2    '"=|${f:1+1:2+2}|"
76 f=01234567; echo 'f:-1:2+2     '"=|${f:-1:2+2}|"
77 f=01234567; echo 'f:1:f        '"=|${f:1:f}|"
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:3:1} '"=|${f:1:${f:3:1}}|"
81 f=01234567; echo 'f:1:1`echo 1`'"=|${f:1:`echo 1`}|"
82
83 echo Done