help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] questions about errexit, pipes to while loops


From: Jonathan Baccash
Subject: [Help-bash] questions about errexit, pipes to while loops
Date: Sun, 25 Mar 2012 20:40:01 +0000

As far as I can tell, the documentation doesn’t match the behavior for bash (using bash 3.1.17) in the following scripts. First, this script works as expected:

 

set -e

cat /dev/zero | false

echo blah $?

 

The script exits with status 1 and does not print blah 1. This one does not appear to work in accordance with docs:

 

set -e

cat /dev/zero | while true; do false; done

echo blah $?

 

The script prints blah 1 and exits with status 0. I expected that, since the command pipeline exits with a failure status, set -e would cause the script as a whole to exit, just as in the previous example. The docs for errexit indicate that “The shell does not exit if the command that fails is part of the command list immediately following a while or until keyword…” I interpret this to mean if the conditional statement fails, the while loop exits with a non-zero exit status, which isn’t the case here. (Regardless, the while loop clearly does exit with non-zero exit status in this case, since the command pipeline as a whole exits with exit status 1.)

 

Another weird thing I noticed is that this:

 

set -e

cat </file/that/doesnt/exist

 

exits with a non-zero exit status, but this:

 

set -e

while true; do false; done </file/that/doesnt/exist

 

does not. Shouldn’t it?

 

Jon.

 

 

 
The contents of this e-mail and any attachments are confidential and only for use by the intended recipient. Any unauthorized use, distribution or copying of this message is strictly prohibited. If you are not the intended recipient please inform the sender immediately by reply e-mail and delete this message from your system. Thank you for your co-operation.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]