param_expand_bash_substring.tests 2.3 KB

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