1#   This program is free software: you can redistribute it and/or modify
2#   it under the terms of the GNU General Public License as published by
3#   the Free Software Foundation, either version 3 of the License, or
4#   (at your option) any later version.
5#
6#   This program is distributed in the hope that it will be useful,
7#   but WITHOUT ANY WARRANTY; without even the implied warranty of
8#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9#   GNU General Public License for more details.
10#
11#   You should have received a copy of the GNU General Public License
12#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
13#
14# basics
15cat <<EOF
16a
17b
18c
19EOF
20read x <<EOF
21a
22b
23c
24EOF
25echo "$x"
26read x y <<\EOF
27$PS4
28EOF
29echo "$x"
30
31# empty here-documents
32read x <<EOF
33EOF
34echo "$x"
35read x <<\EOF
36EOF
37echo "$x"
38read x <<EOF
39$empty
40EOF
41echo "$x"
42
43# check order and content of multiple here docs
44cat << EOF1 << EOF2
45hi
46EOF1
47there
48EOF2
49
50while read line1; do
51	read line2 <&3
52	echo $line1 - $line2
53done <<EOF1 3<<EOF2
54one
55two
56three
57EOF1
58alpha
59beta
60gamma
61EOF2
62
63
64# check quoted here-doc is protected
65
66a=foo
67cat << 'EOF'
68hi\
69there$a
70stuff
71EOF
72
73# check that quoted here-documents don't have \newline processing done
74
75cat << 'EOF'
76hi\
77there
78EO\
79F
80EOF
81true
82
83# check that \newline is removed at start of here-doc
84cat << EO\
85F
86hi
87EOF
88
89# check that \newline removal works for here-doc delimiter
90cat << EOF
91hi
92EO\
93F
94
95# check operation of tab removal in here documents
96cat <<- EOF
97	tab 1
98	tab 2
99	tab 3
100	EOF
101
102# check appending of text to file from here document
103rm -f ${TMPDIR}/bash-zzz
104cat > ${TMPDIR}/bash-zzz << EOF
105abc
106EOF
107cat >> ${TMPDIR}/bash-zzz << EOF
108def ghi
109jkl mno
110EOF
111cat ${TMPDIR}/bash-zzz
112rm -f ${TMPDIR}/bash-zzz
113
114# make sure command printing puts the here-document as the last redirection
115# on the line, and the function export code preserves syntactic correctness
116fff()
117{
118  ed ${TMPDIR}/foo <<ENDOFINPUT >/dev/null
119/^name/d
120w
121q
122ENDOFINPUT
123aa=1
124}
125
126type fff
127export -f fff
128${THIS_SH} -c 'type fff'
129
130${THIS_SH} ./heredoc1.sub
131
132# test heredocs in command substitutions
133${THIS_SH} ./heredoc2.sub
134${THIS_SH} ./heredoc3.sub
135${THIS_SH} ./heredoc4.sub
136
137# heredoc tests that use different size documents to test pipe implementation
138${THIS_SH} ./heredoc5.sub
139
140echo $(
141	cat <<< "comsub here-string"
142)
143
144# check that end of file delimits a here-document
145# THIS MUST BE LAST!
146
147cat << EOF
148hi
149there
150