Suppose the following test-pipefail.sh batch:
#!/usr/bin/env bash
set -eo pipefail
./echoer.sh | head -n1 >/dev/null
echo "Might work with pipefail"
for i in {1..100} ; do
./echoer.sh | head -n1 >/dev/null
done
echo "Stable work with pipefail"
With echoer.sh contents:
#!/usr/bin/env bash
echo 'head (GNU coreutils) 8.30'
echo 'GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)'
exit 0
Expected results of ./test-pipefail.sh:
Might work with pipefail
Stable work with pipefail
Actual behaviour:
Might work with pipefail
or (at random) with no output.
Writer program in pipe never fails if I'm using any binary utility instead of echoer.sh, but it always doesn't work (cause pipefail-script to exit) if writer is shell script (for example, ldd from glibc binary package). Replacing execution (./echoer.sh) in test-pipefail.sh with sourcing (. echoer.sh) leads to increased probability of successful execution, i.e. sometimes I'm getting
Stable work with pipefail
in test-pipefail.sh output.
head always returns success in such pipes. Removing second echo in echoer.sh leads to successfull execution with both sourcing and execution in separate shell.