1 # First try some invalid patterns. Do in subshell due to parsing error.
2 # (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages)
3 "$THIS_SH" -c 'echo ${+} ; echo moo' SHELL
4 "$THIS_SH" -c 'echo ${:+} ; echo moo' SHELL
7 # ${V+word} "if V unset, then substitute nothing, else substitute word"
8 # ${V:+word} "if V unset or '', then substitute nothing, else substitute word"
10 # ${#:+} is a :+ op on $#, but ${#+} (and any other ${#c}) is "length of $c",
12 # bash and dash do not accept ${#+}. it's possible for some shell to skip
13 # the check that c is valid and interpret ${#+} as "len of $+". Not testing it.
16 # Forms with non-empty word work as expected in both ash and bash.
17 echo _${#+z}_ _${#:+z}_
21 echo _$1 _${1+} _${1:+} _${1+word} _${1:+word}
24 echo _$1 _${1+} _${1:+} _${1+word} _${1:+word}
27 echo _$f _${f+} _${f:+} _${f+word} _${f:+word}
30 echo _$f _${f+} _${f:+} _${f+word} _${f:+word}
33 echo _$f _${f+} _${f:+} _${f+word} _${f:+word}