param_expand_indicate_error.tests 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # do all of these in subshells since it's supposed to error out
  2. # (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages)
  3. # first try some invalid patterns
  4. #"$THIS_SH" -c 'echo ${?}' SHELL -- this is valid as it's the same as $?
  5. "$THIS_SH" -c 'echo ${:?}' SHELL
  6. # then some funky ones
  7. # note: bash prints 1 - treats it as "length of $#"
  8. "$THIS_SH" -c 'echo ${#?}' SHELL
  9. # bash prints 0
  10. "$THIS_SH" -c 'echo ${#:?}' SHELL
  11. # now some valid ones
  12. export msg_unset="unset!"
  13. export msg_null_or_unset="null or unset!"
  14. echo ====
  15. "$THIS_SH" -c 'set --; echo _$1' SHELL
  16. "$THIS_SH" -c 'set --; echo _${1?}' SHELL
  17. "$THIS_SH" -c 'set --; echo _${1:?}' SHELL
  18. "$THIS_SH" -c 'set --; echo _${1?message1}' SHELL
  19. "$THIS_SH" -c 'set --; echo _${1:?message1}' SHELL
  20. "$THIS_SH" -c 'set --; echo _${1?$msg_unset}' SHELL
  21. "$THIS_SH" -c 'set --; echo _${1:?$msg_null_or_unset}' SHELL
  22. echo ====
  23. "$THIS_SH" -c 'set -- aaaa; echo _$1' SHELL
  24. "$THIS_SH" -c 'set -- aaaa; echo _${1?}' SHELL
  25. "$THIS_SH" -c 'set -- aaaa; echo _${1:?}' SHELL
  26. "$THIS_SH" -c 'set -- aaaa; echo _${1?word}' SHELL
  27. "$THIS_SH" -c 'set -- aaaa; echo _${1:?word}' SHELL
  28. "$THIS_SH" -c 'set -- aaaa; echo _${1?$msg_unset}' SHELL
  29. "$THIS_SH" -c 'set -- aaaa; echo _${1:?$msg_null_or_unset}' SHELL
  30. echo ====
  31. "$THIS_SH" -c 'unset f; echo _$f' SHELL
  32. "$THIS_SH" -c 'unset f; echo _${f?}' SHELL
  33. "$THIS_SH" -c 'unset f; echo _${f:?}' SHELL
  34. "$THIS_SH" -c 'unset f; echo _${f?message3}' SHELL
  35. "$THIS_SH" -c 'unset f; echo _${f:?message3}' SHELL
  36. "$THIS_SH" -c 'unset f; echo _${f?$msg_unset}' SHELL
  37. "$THIS_SH" -c 'unset f; echo _${f:?$msg_null_or_unset}' SHELL
  38. echo ====
  39. "$THIS_SH" -c 'f=; echo _$f' SHELL
  40. "$THIS_SH" -c 'f=; echo _${f?}' SHELL
  41. "$THIS_SH" -c 'f=; echo _${f:?}' SHELL
  42. "$THIS_SH" -c 'f=; echo _${f?word}' SHELL
  43. "$THIS_SH" -c 'f=; echo _${f:?message4}' SHELL
  44. "$THIS_SH" -c 'f=; echo _${f?$msg_unset}' SHELL
  45. "$THIS_SH" -c 'f=; echo _${f:?$msg_null_or_unset}' SHELL
  46. echo ====
  47. "$THIS_SH" -c 'f=fff; echo _$f' SHELL
  48. "$THIS_SH" -c 'f=fff; echo _${f?}' SHELL
  49. "$THIS_SH" -c 'f=fff; echo _${f:?}' SHELL
  50. "$THIS_SH" -c 'f=fff; echo _${f?word}' SHELL
  51. "$THIS_SH" -c 'f=fff; echo _${f:?word}' SHELL
  52. "$THIS_SH" -c 'f=fff; echo _${f?$msg_unset}' SHELL
  53. "$THIS_SH" -c 'f=fff; echo _${f:?$msg_null_or_unset}' SHELL