]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/heredoc.tests
bash-5.0 distribution sources and documentation
[thirdparty/bash.git] / tests / heredoc.tests
CommitLineData
ccc6cda3
JA
1# check order and content of multiple here docs
2
3cat << EOF1 << EOF2
4hi
5EOF1
6there
7EOF2
8
d166f048
JA
9while read line1; do
10 read line2 <&3
11 echo $line1 - $line2
12done <<EOF1 3<<EOF2
13one
14two
15three
16EOF1
17alpha
18beta
19gamma
20EOF2
21
22
ccc6cda3
JA
23# check quoted here-doc is protected
24
25a=foo
26cat << 'EOF'
27hi\
28there$a
29stuff
30EOF
31
32# check that quoted here-documents don't have \newline processing done
33
34cat << 'EOF'
35hi\
36there
37EO\
38F
39EOF
40true
41
42# check that \newline is removed at start of here-doc
43cat << EO\
44F
45hi
46EOF
47
48# check that \newline removal works for here-doc delimiter
49cat << EOF
50hi
51EO\
52F
53
d166f048
JA
54# check operation of tab removal in here documents
55cat <<- EOF
56 tab 1
57 tab 2
58 tab 3
59 EOF
60
61# check appending of text to file from here document
d233b485
CR
62rm -f ${TMPDIR}/bash-zzz
63cat > ${TMPDIR}/bash-zzz << EOF
d166f048
JA
64abc
65EOF
d233b485 66cat >> ${TMPDIR}/bash-zzz << EOF
d166f048
JA
67def ghi
68jkl mno
69EOF
d233b485
CR
70cat ${TMPDIR}/bash-zzz
71rm -f ${TMPDIR}/bash-zzz
d166f048
JA
72
73# make sure command printing puts the here-document as the last redirection
74# on the line, and the function export code preserves syntactic correctness
75fff()
76{
d233b485 77 ed ${TMPDIR}/foo <<ENDOFINPUT >/dev/null
d166f048
JA
78/^name/d
79w
80q
81ENDOFINPUT
82aa=1
83}
84
85type fff
86export -f fff
87${THIS_SH} -c 'type fff'
88
17345e5a
JA
89${THIS_SH} ./heredoc1.sub
90
ac50fbac
CR
91# test heredocs in command substitutions
92${THIS_SH} ./heredoc2.sub
ac50fbac 93${THIS_SH} ./heredoc3.sub
d233b485 94${THIS_SH} ./heredoc4.sub
ac50fbac 95
0001803f
CR
96echo $(
97 cat <<< "comsub here-string"
98)
99
ccc6cda3
JA
100# check that end of file delimits a here-document
101# THIS MUST BE LAST!
102
103cat << EOF
104hi
105there