On Mon, 2017-04-17 at 15:28 +0100, Jeremy Henty wrote: > In fact "set -e" makes things even stranger. I thought that "this > && that" was equivalent to "if this ; then that ; else false ; fi", > but after "set -e", "false && true" returns status 1 to the shell, > but "if false ; then true ; else false ; fi" makes the shell itself > exit with status 1! > > Is there no end to the "joy" of shell programming! :-) >
Broadly speaking, the point of "set -e" is to exit on unhandled errors. To repeat (and re-format) the definition Pierre quoted: | The shell does not exit if the command that fails is: | * part of the command list immediately following a while | or until keyword | * part of the test following the if or elif reserved words | * part of any command executed in a && or || list except the | command following the final && or || | * any command in a pipeline but the last | * if the command's return value is being inverted with !. So your examples are easy to explain. In the case of "false && true", the expression evaluates to status 1, but the expression meets the third criteria above. The assumption is that if you're using this syntax, the first command is a test, and its failure feeds into the decision not to run the second part. By contrast, in the if-else example, your 'else' condition runs the command 'false' without any attempt to handle the non-zero return, and so doesn't meet any of the criteria above... the -e behaviour is triggered. Simon.
signature.asc
Description: This is a digitally signed message part
-- http://lists.linuxfromscratch.org/listinfo/blfs-support FAQ: http://www.linuxfromscratch.org/blfs/faq.html Unsubscribe: See the above information page
