2010-05-22 06:42:29 +05:30
|
|
|
# first try some invalid patterns
|
2010-05-21 04:45:42 +05:30
|
|
|
# do all of these in subshells since it's supposed to error out
|
2017-07-25 18:25:05 +05:30
|
|
|
# (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages)
|
2010-05-21 04:45:42 +05:30
|
|
|
export var=0123456789
|
2017-07-25 18:25:05 +05:30
|
|
|
"$THIS_SH" -c 'echo ${:}' SHELL
|
|
|
|
"$THIS_SH" -c 'echo ${::}' SHELL
|
|
|
|
"$THIS_SH" -c 'echo ${:1}' SHELL
|
|
|
|
"$THIS_SH" -c 'echo ${::1}' SHELL
|
2010-05-21 04:45:42 +05:30
|
|
|
|
2017-07-25 18:25:05 +05:30
|
|
|
#this also is not valid in bash, hush accepts it:
|
|
|
|
"$THIS_SH" -c 'echo ${var:}' SHELL
|
2010-05-21 04:45:42 +05:30
|
|
|
|
|
|
|
# then some funky ones
|
|
|
|
# UNFIXED BUG: this should work: "$THIS_SH" -c 'echo ${?:0}'
|
|
|
|
|
|
|
|
# now some valid ones
|
2010-05-22 06:42:29 +05:30
|
|
|
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 09:50:26 +05:30
|
|
|
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 06:42:29 +05:30
|
|
|
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
|