On 1/5/16 11:47 AM, c...@cs.toronto.edu wrote: > Bash Version: 4.3 > Patch Level: 11 > Release Status: release > > Description: > > If Bash writes to stdout with the built in echo and gets a SIGPIPE, > it can incorrectly buffer and then repeat this would-have-been output > in at least $(...) things invoked in a cleanup function and in fact > in some other contexts as well. To see this in action, create the > following script as /tmp/repro: > > #!/bin/bash > function cleanup() { > r1=$(/bin/echo one) > r2=$(/bin/echo two) > echo $r1 '!' $r2 1>&2 > #echo $r1 '!' $r2 >>/tmp/logout > } > trap cleanup EXIT > sleep 1 > echo final > > Run it as '/tmp/repro | false'. The output produced is the clearly > incorrect: > $ /tmp/repro | false > final > one final ! two final
Thanks for the report. This appears to be easily reproducible on Linux. Adding a call to fpurge() to discard buffered output on stdout before dup2() replaces file descriptor 1 in the child process fixes it. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/