2010-05-22 01:12:29 +00:00
|
|
|
# first try some invalid patterns
|
2010-05-20 23:15:42 +00:00
|
|
|
# do all of these in subshells since it's supposed to error out
|
|
|
|
export var=0123456789
|
|
|
|
"$THIS_SH" -c 'echo ${:}'
|
|
|
|
"$THIS_SH" -c 'echo ${::}'
|
|
|
|
"$THIS_SH" -c 'echo ${:1}'
|
|
|
|
"$THIS_SH" -c 'echo ${::1}'
|
|
|
|
|
|
|
|
#this also is not valid in bash, but we accept it:
|
|
|
|
"$THIS_SH" -c 'echo ${var:}'
|
|
|
|
|
|
|
|
# then some funky ones
|
|
|
|
# UNFIXED BUG: this should work: "$THIS_SH" -c 'echo ${?:0}'
|
|
|
|
|
|
|
|
# now some valid ones
|
2010-05-22 01:12:29 +00:00
|
|
|
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::}|"
|
|
|
|
|
2010-05-22 04:20:26 +00:00
|
|
|
echo "Substrings from special vars"
|
|
|
|
echo '? '"=|$?|"
|
|
|
|
echo '?:1 '"=|${?:1}|"
|
|
|
|
echo '?:1:2'"=|${?:1:2}|"
|
|
|
|
echo '?::2 '"=|${?::2}|"
|
|
|
|
echo '?:1: '"=|${?:1:}|"
|
|
|
|
echo '?:: '"=|${?::}|"
|
|
|
|
set -- 1 2 3 4 5 6 7 8 9 10 11
|
|
|
|
echo '# '"=|$#|"
|
|
|
|
echo '#:1 '"=|${#:1}|"
|
|
|
|
echo '#:1:2'"=|${#:1:2}|"
|
|
|
|
echo '#::2 '"=|${#::2}|"
|
|
|
|
echo '#:1: '"=|${#:1:}|"
|
|
|
|
echo '#:: '"=|${#::}|"
|
|
|
|
|
2010-05-22 01:12:29 +00:00
|
|
|
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
|