1export LC_ALL=C
2export LANG=C
3
4# catch-all for remaining untested redirection stuff
5set +o posix
6
7echo abc > /tmp/redir-test
8cat /tmp/redir-test
9
10set -o noclobber
11
12#this should be an error
13echo def > /tmp/redir-test
14cat /tmp/redir-test
15
16# but this should succeed
17echo def > /tmp/redir-test-2
18cat /tmp/redir-test-2
19
20# and so should this
21echo def >| /tmp/redir-test
22cat /tmp/redir-test
23
24set +o noclobber
25rm /tmp/redir-test /tmp/redir-test-2
26
27# this should be an error
28z="a b"
29cat < $z
30
31echo "Point 1"
32
33exec 3</etc/passwd
34exec 4>/tmp/bash-a
35exec 5>/tmp/bash-b
36echo "Point 2"
37
38echo to a 1>&4
39echo to b 1>&5
40cat /tmp/bash-a
41cat /tmp/bash-b
42exec 11</dev/null
43echo "Point 3"
44
45echo to a 1>&4
46echo to b 1>&5
47cat /tmp/bash-a
48cat /tmp/bash-b
49
50exec 11<&-
51echo "Point 4"
52
53exec 6<>/tmp/bash-c
54echo to c 1>&6
55cat /tmp/bash-c
56echo "Point 5"
57
58rm -f /tmp/bash-a /tmp/bash-b /tmp/bash-c
59
60#
61# Test the effect of input buffering on the shell's input
62#
63${THIS_SH} < redir1.sub
64
65# more open, close, duplicate file descriptors
66${THIS_SH} ./redir3.sub < ./redir3.in1
67
68# still more redirections
69${THIS_SH} ./redir4.sub < redir4.in1
70
71# various forms of null redirection
72testf()
73{
74	if [ -f "$1" ]; then
75		rm -f "$1"
76	else
77		echo oops -- $1 not found
78	fi
79}
80
81> /tmp/null-redir-a
82testf /tmp/null-redir-a
83
84$EXIT > /tmp/null-redir-b
85testf /tmp/null-redir-b
86
87( > /tmp/null-redir-c )
88testf /tmp/null-redir-c
89
90$EXIT > /tmp/null-redir-d &
91wait
92testf /tmp/null-redir-d
93
94exit 3 | $EXIT > /tmp/null-redir-e
95echo $? -- ${PIPESTATUS[@]}
96testf /tmp/null-redir-e
97
98exit 4 | > /tmp/null-redir-f
99echo $? -- ${PIPESTATUS[@]}
100testf /tmp/null-redir-f
101
102> /tmp/null-redir-g &
103wait
104testf /tmp/null-redir-g
105
106exec >/tmp/null-redir-h &
107wait
108testf /tmp/null-redir-h
109
110# make sure async commands don't get /dev/null as stdin when an explicit
111# input redirection is supplied
112for x in 1 2 3; do
113	{ read line ; echo $line ; } &
114	wait
115	{ read line ; echo $line ; } &
116	wait
117done << EOF
118ab
119cd
120ef
121gh
122ij
123kl
124EOF
125
126# make sure async commands get /dev/null as stdin in the absence of any
127# input redirection
128/bin/cat &
129wait
130echo $?
131
132# make sure that loops work OK with here documents and are not run in
133# subshells
134while read line; do
135	echo $line
136	l2=$line
137done << EOF
138ab
139cd
140EOF
141echo $l2
142
143# These should not echo anything -- bug in versions before 2.04
144( ( echo hello 1>&3 ) 3>&1 ) >/dev/null 2>&1
145
146( ( echo hello 1>&3 ) 3>&1 ) >/dev/null 2>&1 | cat
147
148# in posix mode, non-interactive shells are not allowed to perform
149# filename expansion on input redirections, even if they expand to
150# a single filename
151set -o posix
152cat < redir1.*
153
154# test ksh93 dup-and-close (move fd) redirections
155${THIS_SH} ./redir5.sub
156
157# test behavior after a write error with a builtin command
158${THIS_SH} ./redir6.sub
159
160# problem with redirections using fds bash uses internally
161: ${TMPDIR:=/tmp}
162
163trap 'rm -f $TMPDIR/bash-redir-$$' 0 1 2 3 6 15
164
165echo before block
166{
167	echo before redir
168	exec 10>&1
169	echo after redir
170} > $TMPDIR/bash-redir-$$
171
172echo after block
173
174${THIS_SH} ./redir7.sub
175