summaryrefslogtreecommitdiff
path: root/tests/heredoc.tests
blob: 79bf4ce72255b5860fc1f8e8dcc0bf36ad6dd476 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# check order and content of multiple here docs

cat << EOF1 << EOF2 
hi
EOF1
there
EOF2

while read line1; do
	read line2 <&3
	echo $line1 - $line2
done <<EOF1 3<<EOF2
one
two
three
EOF1
alpha
beta
gamma
EOF2


# check quoted here-doc is protected

a=foo
cat << 'EOF'
hi\
there$a
stuff
EOF

# check that quoted here-documents don't have \newline processing done

cat << 'EOF'
hi\
there
EO\
F
EOF
true

# check that \newline is removed at start of here-doc
cat << EO\
F
hi
EOF

# check that \newline removal works for here-doc delimiter
cat << EOF
hi
EO\
F

# check operation of tab removal in here documents
cat <<- EOF
	tab 1
	tab 2
	tab 3
	EOF

# check appending of text to file from here document
rm -f /tmp/bash-zzz
cat > /tmp/bash-zzz << EOF
abc
EOF
cat >> /tmp/bash-zzz << EOF
def ghi
jkl mno
EOF
cat /tmp/bash-zzz
rm -f /tmp/bash-zzz

# make sure command printing puts the here-document as the last redirection
# on the line, and the function export code preserves syntactic correctness
fff()
{
  ed /tmp/foo <<ENDOFINPUT >/dev/null
/^name/d
w
q
ENDOFINPUT
aa=1
}

type fff
export -f fff
${THIS_SH} -c 'type fff'

${THIS_SH} ./heredoc1.sub

echo $(
	cat <<< "comsub here-string"
)

# check that end of file delimits a here-document
# THIS MUST BE LAST!

cat << EOF
hi
there