3
0

param_expand_alt.tests 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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
  5. # now some funky ones.
  6. # ${V+word} "if V unset, then substitute nothing, else substitute word"
  7. # ${V:+word} "if V unset or '', then substitute nothing, else substitute word"
  8. #
  9. # ${#:+} is a :+ op on $#, but ${#+} (and any other ${#c}) is "length of $c",
  10. # not + op on $#.
  11. # bash and dash do not accept ${#+}. it's possible for some shell to skip
  12. # the check that c is valid and interpret ${#+} as "len of $+". Not testing it.
  13. # echo _${#+}_
  14. echo _${#:+}_
  15. # Forms with non-empty word work as expected in both ash and bash.
  16. echo _${#+z}_ _${#:+z}_
  17. # now some valid ones
  18. set --
  19. echo _$1 _${1+} _${1:+} _${1+word} _${1:+word}
  20. set -- aaaa
  21. echo _$1 _${1+} _${1:+} _${1+word} _${1:+word}
  22. unset f
  23. echo _$f _${f+} _${f:+} _${f+word} _${f:+word}
  24. f=
  25. echo _$f _${f+} _${f:+} _${f+word} _${f:+word}
  26. f=fff
  27. echo _$f _${f+} _${f:+} _${f+word} _${f:+word}