blob: aa72bcb763e6124c8536572b034e56f909995bb4 (
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
|
# Redirections.
echo one >f; echo two >>f; cat f
cat <f >g; cat g
exec 3>h; echo to3 >&3; exec 3>&-; cat h
exec 4<f; read -r l <&4; echo "$l"; read -r l <&4; echo "$l"; exec 4<&-
{ echo out; echo err >&2; } >both 2>&1; sort both
{ echo out; echo err >&2; } 2>&1 >/dev/null
( echo sub-out; echo sub-err >&2 ) 2>&1 | sort
exec 5>&1; echo via5 >&5; exec 5>&-
(echo x >&9) 2>/dev/null; echo "bad fd=$?"
(cat <nofile) 2>/dev/null; echo "missing=$?"
: >ro; set -C; (echo x >ro) 2>/dev/null; echo "noclobber=$?"
echo forced >|ro; cat ro; set +C
echo rw >rwf; cat 1<>rwf
echo data 1<>rw2; cat rw2
>empty; [ -s empty ] || echo empty-created
x=$(echo captured 2>&1); echo "$x"
f() { echo "fn out"; echo "fn err" >&2; }
f 2>&1 >/dev/null | tr a-z A-Z
f >fo 2>&1; sort fo
for i in 1 2; do echo $i; done >loop; cat loop
while read -r l; do echo "<$l>"; done <f
if true; then echo in-if; fi >iff; cat iff
case x in x) echo in-case ;; esac 2>&1 >cf; cat cf
exec 6>sixf; echo six >&6; exec 6>&-; cat sixf
echo dup-close 3>&1 >&3 3>&-
cat <<END 3<f
heredoc with another redirection
END
echo "multiple" >m1 >m2; cat m1; cat m2 | wc -c | tr -d ' '
ls nofile 2>&1 >/dev/null | wc -l | tr -d ' '
exec 7<&0; exec 0</dev/null; read -r l; echo "stdin at eof read=$?"; exec 0<&7 7<&-
: 2>/dev/null >redir-only; [ -f redir-only ] && echo created
|