1 | export LC_ALL=C
|
---|
2 | export LANG=C
|
---|
3 |
|
---|
4 | # catch-all for remaining untested redirection stuff
|
---|
5 | set +o posix
|
---|
6 |
|
---|
7 | echo abc > /tmp/redir-test
|
---|
8 | cat /tmp/redir-test
|
---|
9 |
|
---|
10 | set -o noclobber
|
---|
11 |
|
---|
12 | #this should be an error
|
---|
13 | echo def > /tmp/redir-test
|
---|
14 | cat /tmp/redir-test
|
---|
15 |
|
---|
16 | # but this should succeed
|
---|
17 | echo def > /tmp/redir-test-2
|
---|
18 | cat /tmp/redir-test-2
|
---|
19 |
|
---|
20 | # and so should this
|
---|
21 | echo def >| /tmp/redir-test
|
---|
22 | cat /tmp/redir-test
|
---|
23 |
|
---|
24 | set +o noclobber
|
---|
25 | rm /tmp/redir-test /tmp/redir-test-2
|
---|
26 |
|
---|
27 | # this should be an error
|
---|
28 | z="a b"
|
---|
29 | cat < $z
|
---|
30 |
|
---|
31 | echo "Point 1"
|
---|
32 |
|
---|
33 | exec 3</etc/passwd
|
---|
34 | exec 4>/tmp/bash-a
|
---|
35 | exec 5>/tmp/bash-b
|
---|
36 | echo "Point 2"
|
---|
37 |
|
---|
38 | echo to a 1>&4
|
---|
39 | echo to b 1>&5
|
---|
40 | cat /tmp/bash-a
|
---|
41 | cat /tmp/bash-b
|
---|
42 | exec 11</dev/null
|
---|
43 | echo "Point 3"
|
---|
44 |
|
---|
45 | echo to a 1>&4
|
---|
46 | echo to b 1>&5
|
---|
47 | cat /tmp/bash-a
|
---|
48 | cat /tmp/bash-b
|
---|
49 |
|
---|
50 | exec 11<&-
|
---|
51 | echo "Point 4"
|
---|
52 |
|
---|
53 | exec 6<>/tmp/bash-c
|
---|
54 | echo to c 1>&6
|
---|
55 | cat /tmp/bash-c
|
---|
56 | echo "Point 5"
|
---|
57 |
|
---|
58 | rm -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
|
---|
72 | testf()
|
---|
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
|
---|
82 | testf /tmp/null-redir-a
|
---|
83 |
|
---|
84 | $EXIT > /tmp/null-redir-b
|
---|
85 | testf /tmp/null-redir-b
|
---|
86 |
|
---|
87 | ( > /tmp/null-redir-c )
|
---|
88 | testf /tmp/null-redir-c
|
---|
89 |
|
---|
90 | $EXIT > /tmp/null-redir-d &
|
---|
91 | wait
|
---|
92 | testf /tmp/null-redir-d
|
---|
93 |
|
---|
94 | exit 3 | $EXIT > /tmp/null-redir-e
|
---|
95 | echo $? -- ${PIPESTATUS[@]}
|
---|
96 | testf /tmp/null-redir-e
|
---|
97 |
|
---|
98 | exit 4 | > /tmp/null-redir-f
|
---|
99 | echo $? -- ${PIPESTATUS[@]}
|
---|
100 | testf /tmp/null-redir-f
|
---|
101 |
|
---|
102 | > /tmp/null-redir-g &
|
---|
103 | wait
|
---|
104 | testf /tmp/null-redir-g
|
---|
105 |
|
---|
106 | exec >/tmp/null-redir-h &
|
---|
107 | wait
|
---|
108 | testf /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
|
---|
112 | for x in 1 2 3; do
|
---|
113 | { read line ; echo $line ; } &
|
---|
114 | wait
|
---|
115 | { read line ; echo $line ; } &
|
---|
116 | wait
|
---|
117 | done << EOF
|
---|
118 | ab
|
---|
119 | cd
|
---|
120 | ef
|
---|
121 | gh
|
---|
122 | ij
|
---|
123 | kl
|
---|
124 | EOF
|
---|
125 |
|
---|
126 | # make sure async commands get /dev/null as stdin in the absence of any
|
---|
127 | # input redirection
|
---|
128 | /bin/cat &
|
---|
129 | wait
|
---|
130 | echo $?
|
---|
131 |
|
---|
132 | # make sure that loops work OK with here documents and are not run in
|
---|
133 | # subshells
|
---|
134 | while read line; do
|
---|
135 | echo $line
|
---|
136 | l2=$line
|
---|
137 | done << EOF
|
---|
138 | ab
|
---|
139 | cd
|
---|
140 | EOF
|
---|
141 | echo $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
|
---|
151 | set -o posix
|
---|
152 | cat < 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 |
|
---|
163 | trap 'rm -f $TMPDIR/bash-redir-$$' 0 1 2 3 6 15
|
---|
164 |
|
---|
165 | echo before block
|
---|
166 | {
|
---|
167 | echo before redir
|
---|
168 | exec 10>&1
|
---|
169 | echo after redir
|
---|
170 | } > $TMPDIR/bash-redir-$$
|
---|
171 |
|
---|
172 | echo after block
|
---|
173 |
|
---|
174 | ${THIS_SH} ./redir7.sub
|
---|