heredoc.tests 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # check order and content of multiple here docs
  2. cat << EOF1 << EOF2
  3. hi
  4. EOF1
  5. there
  6. EOF2
  7. while read line1; do
  8. read line2 <&3
  9. echo $line1 - $line2
  10. done <<EOF1 3<<EOF2
  11. one
  12. two
  13. three
  14. EOF1
  15. alpha
  16. beta
  17. gamma
  18. EOF2
  19. # check quoted here-doc is protected
  20. a=foo
  21. cat << 'EOF'
  22. hi\
  23. there$a
  24. stuff
  25. EOF
  26. # check that quoted here-documents don't have \newline processing done
  27. cat << 'EOF'
  28. hi\
  29. there
  30. EO\
  31. F
  32. EOF
  33. true
  34. # check that \newline is removed at start of here-doc
  35. cat << EO\
  36. F
  37. hi
  38. EOF
  39. #ash# # check that \newline removal works for here-doc delimiter
  40. #ash# cat << EOF
  41. #ash# hi
  42. #ash# EO\
  43. #ash# F
  44. # check operation of tab removal in here documents
  45. cat <<- EOF
  46. tab 1
  47. tab 2
  48. tab 3
  49. EOF
  50. # check appending of text to file from here document
  51. rm -f /tmp/bash-zzz
  52. cat > /tmp/bash-zzz << EOF
  53. abc
  54. EOF
  55. cat >> /tmp/bash-zzz << EOF
  56. def ghi
  57. jkl mno
  58. EOF
  59. cat /tmp/bash-zzz
  60. rm -f /tmp/bash-zzz
  61. # make sure command printing puts the here-document as the last redirection
  62. # on the line, and the function export code preserves syntactic correctness
  63. fff()
  64. {
  65. ed /tmp/foo <<ENDOFINPUT >/dev/null
  66. /^name/d
  67. w
  68. q
  69. ENDOFINPUT
  70. aa=1
  71. }
  72. type fff
  73. #ash# export -f fff
  74. #ash# ${THIS_SH} -c 'type fff'
  75. # check that end of file delimits a here-document
  76. # THIS MUST BE LAST!
  77. cat << EOF
  78. hi
  79. there