On Mon, Nov 9, 2009 at 4:49 AM, Chet Ramey <chet.ra...@case.edu> wrote: > Ciprian Dorin, Craciun wrote: >> Shouldn't any of the following scripts print `error`? (Bash >> 4.0.35(2)-release on ArchLinux.) >> >> Or I've miss-interpreted the documentation... >> >> Thanks, >> Ciprian. >> >> >> ~~~~ >> set -e -o pipefail >> ( false ; echo ok ; ) || echo error >> ~~~~ >> >> ~~~~ >> set -e -o pipefail >> ( false ; echo ok ; ) | true || echo error >> ~~~~ >> >> ~~~~ >> set -e -o pipefail >> { false ; echo ok ; } || echo error >> ~~~~ >> >> ~~~~ >> set -e -o pipefail >> { false ; echo ok ; } | true || echo error >> ~~~~ > > No. Since `set -e' has no effect on the left side of the || or && > operators, all of the commands preceding the || exit with status 0. > > 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/
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.