Ciprian Dorin, Craciun wrote: >> Sorry, but I don't understand at all... So please bare with me and >> make me understand. >> >> So I've interpreted `set -e` as a way to tell bash to treat any >> process exiting with non-zero (and not succeeded by a || ), as an >> error and end the current shell / sub-shell. >> >> Thus if I say: `set -e ; { false ; true ; }` it works, but when I >> put the `||`, it doesn't... >> >> So my question is how can I solve this problem? (And obtain the >> needed behaviour.) (I see `()` and `{}` as blocks in normal >> programming languages (of course with some particularities), and >> non-zero exit codes as exceptions. And this is very helpful to write >> robust bash scripts.) >> >> Thanks, >> Ciprian. > > I'm also pasting from the documentation. > > The interesting part is :`The shell does not exit if the command > that fails is part of the command list immediately following [...] > part of any command executed in a && or |⎪ list, [...], The > option applies to [...] each sub-shell environment [...] and may cause > subshells to exit before executing all the commands in the subshell`. > > So from this I understand that the (parent) shell doesn't exit if > the (child) sub-shell fails and is at left of `||`. But that the > subshell inherits the `-e` option, and should exit.
The subshell does inherit the -e option. However, it also inherits the knowledge that it's the lhs of ||, which cancels the effect of set -e. The setting is ignored and enabling it has no effect. (This is actually historical sh behavior that the Posix working group attempted to codify last spring.) Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/