]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/heredoc.tests
Bash-5.2-rc4 release
[thirdparty/bash.git] / tests / heredoc.tests
CommitLineData
8868edaf
CR
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"
ccc6cda3 42
8868edaf 43# check order and content of multiple here docs
ccc6cda3
JA
44cat << EOF1 << EOF2
45hi
46EOF1
47there
48EOF2
49
d166f048
JA
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
ccc6cda3
JA
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
d166f048
JA
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
d233b485
CR
103rm -f ${TMPDIR}/bash-zzz
104cat > ${TMPDIR}/bash-zzz << EOF
d166f048
JA
105abc
106EOF
d233b485 107cat >> ${TMPDIR}/bash-zzz << EOF
d166f048
JA
108def ghi
109jkl mno
110EOF
d233b485
CR
111cat ${TMPDIR}/bash-zzz
112rm -f ${TMPDIR}/bash-zzz
d166f048
JA
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{
d233b485 118 ed ${TMPDIR}/foo <<ENDOFINPUT >/dev/null
d166f048
JA
119/^name/d
120w
121q
122ENDOFINPUT
123aa=1
124}
125
126type fff
127export -f fff
128${THIS_SH} -c 'type fff'
129
17345e5a
JA
130${THIS_SH} ./heredoc1.sub
131
ac50fbac
CR
132# test heredocs in command substitutions
133${THIS_SH} ./heredoc2.sub
ac50fbac 134${THIS_SH} ./heredoc3.sub
d233b485 135${THIS_SH} ./heredoc4.sub
ac50fbac 136
8868edaf
CR
137# heredoc tests that use different size documents to test pipe implementation
138${THIS_SH} ./heredoc5.sub
139
4491c030
CR
140# test $'...' and $"..." quoted strings in here-documents
141${THIS_SH} ./heredoc6.sub
142
143# interaction between here-documents and command substitutions
144${THIS_SH} ./heredoc7.sub
145
146
0001803f
CR
147echo $(
148 cat <<< "comsub here-string"
149)
150
ccc6cda3
JA
151# check that end of file delimits a here-document
152# THIS MUST BE LAST!
153
154cat << EOF
155hi
156there