heredoc_backslash1.tests 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Test for correct handling of backslashes.
  2. # Note that some lines in each heredoc start with a tab.
  3. a=qwerty
  4. echo Quoted heredoc:
  5. cat <<"EOF1"
  6. a\
  7. b
  8. a\\
  9. b
  10. 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
  11. -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
  12. 123456 `echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-'`
  13. 123456 $(echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-')
  14. c\
  15. EOF1
  16. echo
  17. echo Unquoted heredoc:
  18. cat <<EOF2
  19. a\
  20. b
  21. a\\
  22. b
  23. 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
  24. -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
  25. 123456 `echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-'`
  26. 123456 $(echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-')
  27. c\
  28. EOF2
  29. EOF2
  30. echo
  31. echo Quoted -heredoc:
  32. cat <<-"EOF3"
  33. a\
  34. b
  35. a\\
  36. b
  37. 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
  38. -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
  39. 123456 `echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-'`
  40. 123456 $(echo v'-$a-\t-\\-\"-\'-\`-\--\z-\*-\?-')
  41. c\
  42. EOF3
  43. # In -heredoc case the marker is detected even if it is indented.
  44. echo
  45. echo Unquoted -heredoc:
  46. cat <<-EOF4
  47. a\
  48. b
  49. a\\
  50. b
  51. 123456 -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
  52. -$a-\t-\\-\"-\'-\`-\--\z-\*-\?-
  53. 123456 `echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-'`
  54. 123456 $(echo v'-$a-\t-\\-\"-\x-\`-\--\z-\*-\?-')
  55. c\
  56. EOF4
  57. EOF4
  58. # The marker is not detected if preceding line ends in backslash.
  59. # TODO: marker should be detected even if it is split by line continuation:
  60. # EOF\
  61. # 4
  62. # but currently hush doesn't do it. (Tab before "4" is not allowed, though.)
  63. echo
  64. echo "Done: $?"