I'm using a pipe of several commands in bash. Is there a way of configuring bash to terminate all commands in the whole pipeline immediately should one of the commands fail?
In my case, the first command, say command1
, runs for a while until it produces some output. You might substitute command1
by (sleep 5 && echo "Hello")
, for instance.
Now, command1 | false
does fail after 5 seconds but not immediately.
This behavior seems to have something to do with the amount of output the command produces. For instance, find / | false
returns immediately.
In general, I wonder why bash behaves like this. Can anyone imagine any situation where it is useful that code like command1 | non-existing-command
does not exit at once?
PS: Using temporary files is not an option for me, as the intermediate results I pipe around are to big to be stored.
PPS: Neither set -e
nor set -o pipefail
seem to influence this phenomenon.