[ILUG] bash v4 bug with `coproc' and `wait'? (No,
just bash being silly.)
Brian Foster
blf at utvinternet.ie
Tue May 15 10:02:41 IST 2012
is this a bash(1) v4 bug, or am I missing something?
script:
=====(cut here and below)=====script `t'=====
#!/bin/bash
echo "${BASH_VERSION[@]}"
SLEEP=${SLEEP:-sleep}
report() {
echo -n ${1:?} wait returned ${2:?}
if [ $2 -eq ${3:?} ]; then
echo \ ... Ok
else
echo \ not expected $3
fi
}
want=17
( exit $want ) &
$SLEEP 1 # simulate some processing
wait $!
report 1st $? $want
want=42
coproc { exit 42; }
$SLEEP 1 # simulate some processing
wait $COPROC_PID
report 2nd $? $want
want=55
coproc exit $want
$SLEEP 1 # simulate some processing
wait $COPROC_PID
report 3rd $? $want
want=69
coproc ( exit $want )
$SLEEP 1 # simulate some processing
wait $COPROC_PID
report 4th $? $want
=====(cut here and below)=====script `t'=====
output:
=====(cut here and below)=====output of above script=====
$ bash ./t
4.2.10(1)-release
1st wait returned 17 ... Ok
2nd wait returned 0 not expected 42
3rd wait returned 0 not expected 55
4th wait returned 0 not expected 69
$
$ SLEEP=: bash ./t
4.2.10(1)-release
1st wait returned 17 ... Ok
2nd wait returned 42 ... Ok
3rd wait returned 55 ... Ok
4th wait returned 69 ... Ok
$
=====(cut here and above)=====output of above script=====
it seems to be the case that if the `wait'
is done after the coprocess has exited,
then its status ($?) is always 0, unlike
background (&) processes. huh???
LATE UPDATE:- ah! no! got it... what's
happening is COPROC_PID is being unset,
and so the `wait $COPROC_PID' is turning
into a simple `wait' (no PID(s)), which
in this case _should_ return 0.
prove by using: wait ${COPROC_PID:?}
silly bash. silly silly bash.
cheers!
-blf-
--
“How many surrealists does it take to | Brian Foster
change a lightbulb? Three. One calms | somewhere in south of France
the warthog, and two fill the bathtub | Stop E$$o (ExxonMobil)!
with brightly-coloured machine tools.” | http://www.stopesso.com
More information about the ILUG
mailing list