]> git.ipfire.org Git - thirdparty/bash.git/blob - tests/coproc.tests
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / tests / coproc.tests
1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
5 #
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
10 #
11 # You should have received a copy of the GNU General Public License
12 # along with this program. If not, see <http://www.gnu.org/licenses/>.
13 #
14 : ${TMPDIR:=/tmp}
15 TMPOUT=${TMPDIR}/coproc-wait-$BASHPID
16
17 coproc { echo a b c; sleep 2; }
18
19 case $COPROC_PID in
20 [0-9]*) ;;
21 *) echo COPROC_PID not integer ;;
22 esac
23
24 echo ${COPROC[@]}
25
26 read LINE <&${COPROC[0]}
27 echo $LINE
28
29 wait $COPROC_PID
30
31 coproc REFLECT { cat - ; }
32
33 case $REFLECT_PID in
34 [0-9]*) ;;
35 *) echo REFLECT_PID not integer ;;
36 esac
37
38 echo ${REFLECT[@]}
39
40 echo flop >&${REFLECT[1]}
41 read LINE <&${REFLECT[0]}
42
43 echo $LINE
44
45 { sleep 1; kill $REFLECT_PID; } &
46 wait $REFLECT_PID >$TMPOUT 2>&1 || { status=$? ; echo "coproc.tests: REFLECT: status $status" ; }
47 [[ $status < 128 || $status == 143 ]] || {
48 echo "coproc.tests: wait for REFLECT failed" >&2
49 }
50 rm -f $TMPOUT
51 exec 2>&1
52
53 coproc xcase -n -u
54
55 case $COPROC_PID in
56 [0-9]*) ;;
57 *) echo COPROC_PID not integer ;;
58 esac
59
60 echo ${COPROC[@]}
61
62 echo foo >&${COPROC[1]}
63 read <&${COPROC[0]}
64
65 echo $REPLY
66 echo ${COPROC[@]}
67
68 cat /etc/passwd | grep root | awk -F: '{print $1;}' | sed 1q
69
70 exec 4<&${COPROC[0]}-
71 exec >&${COPROC[1]}-
72
73 echo ${COPROC[@]}
74
75 read foo <&4
76 echo $foo >&2
77
78 exit 0