param_expand_bash_substring.tests 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # first try some invalid patterns
  2. # do all of these in subshells since it's supposed to error out
  3. # (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages)
  4. export var=0123456789
  5. "$THIS_SH" -c 'echo ${:}' SHELL
  6. "$THIS_SH" -c 'echo ${::}' SHELL
  7. "$THIS_SH" -c 'echo ${:1}' SHELL
  8. "$THIS_SH" -c 'echo ${::1}' SHELL
  9. #this also is not valid in bash, hush accepts it:
  10. "$THIS_SH" -c 'echo ${var:}' SHELL
  11. # then some funky ones
  12. "$THIS_SH" -c 'echo ${?:0}' SHELL
  13. # now some valid ones
  14. set --; echo "1 =|${1}|"
  15. set --; echo "1:1 =|${1:1}|"
  16. set --; echo "1:1:2=|${1:1:2}|"
  17. set --; echo "1::2 =|${1::2}|"
  18. set --; echo "1:1: =|${1:1:}|"
  19. set --; echo "1:: =|${1::}|"
  20. set -- 0123; echo "1 =|${1}|"
  21. set -- 0123; echo "1:1 =|${1:1}|"
  22. set -- 0123; echo "1:1:2=|${1:1:2}|"
  23. set -- 0123; echo "1::2 =|${1::2}|"
  24. set -- 0123; echo "1:1: =|${1:1:}|"
  25. set -- 0123; echo "1:: =|${1::}|"
  26. unset f; echo "f =|$f|"
  27. unset f; echo "f:1 =|${f:1}|"
  28. unset f; echo "f:1:2=|${f:1:2}|"
  29. unset f; echo "f::2 =|${f::2}|"
  30. unset f; echo "f:1: =|${f:1:}|"
  31. unset f; echo "f:: =|${f::}|"
  32. f=; echo "f =|$f|"
  33. f=; echo "f:1 =|${f:1}|"
  34. f=; echo "f:1:2=|${f:1:2}|"
  35. f=; echo "f::2 =|${f::2}|"
  36. f=; echo "f:1: =|${f:1:}|"
  37. f=; echo "f:: =|${f::}|"
  38. f=a; echo "f =|$f|"
  39. f=a; echo "f:1 =|${f:1}|"
  40. f=a; echo "f:1:2=|${f:1:2}|"
  41. f=a; echo "f::2 =|${f::2}|"
  42. f=a; echo "f:1: =|${f:1:}|"
  43. f=a; echo "f:: =|${f::}|"
  44. f=0123456789; echo "f =|$f|"
  45. f=0123456789; echo "f:1 =|${f:1}|"
  46. f=0123456789; echo "f:1:2=|${f:1:2}|"
  47. f=0123456789; echo "f::2 =|${f::2}|"
  48. f=0123456789; echo "f:1: =|${f:1:}|"
  49. f=0123456789; echo "f:: =|${f::}|"
  50. echo "Substrings from special vars"
  51. echo '? '"=|$?|"
  52. echo '?:1 '"=|${?:1}|"
  53. echo '?:1:2'"=|${?:1:2}|"
  54. echo '?::2 '"=|${?::2}|"
  55. echo '?:1: '"=|${?:1:}|"
  56. echo '?:: '"=|${?::}|"
  57. set -- 1 2 3 4 5 6 7 8 9 10 11
  58. echo '# '"=|$#|"
  59. echo '#:1 '"=|${#:1}|"
  60. echo '#:1:2'"=|${#:1:2}|"
  61. echo '#::2 '"=|${#::2}|"
  62. echo '#:1: '"=|${#:1:}|"
  63. echo '#:: '"=|${#::}|"
  64. echo "Substrings with expressions"
  65. f=01234567; echo 'f '"=|$f|"
  66. f=01234567; echo 'f:1+1:2+2 '"=|${f:1+1:2+2}|"
  67. f=01234567; echo 'f:-1:2+2 '"=|${f:-1:2+2}|"
  68. f=01234567; echo 'f:1:f '"=|${f:1:f}|"
  69. f=01234567; echo 'f:1:$f '"=|${f:1:$f}|"
  70. f=01234567; echo 'f:1:${f} '"=|${f:1:${f}}|"
  71. f=01234567; echo 'f:1:${f:3:1} '"=|${f:1:${f:3:1}}|"
  72. f=01234567; echo 'f:1:1`echo 1`'"=|${f:1:`echo 1`}|"
  73. echo Done