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
find / |false
fails faster because the first write(2)
system call from find
fails with the error EPIPE
(Broken pipe). This is because false
has been already terminated and hence the pipe between these two commands has been closed already on one side.
If find
would ignore that error (it could do so in theory) it would by also "fail slow".
(sleep 5 && echo "Hello") | false
is "fail slow", because the first part, sleep
, does not "test" the pipe by writing to it. After 5 seconds the echo
also get the EPIPE
error. Whether this error terminates the first part in this case or not is not important to the question.