>> [...set -e vs shell functions...]

> Does this achieve what you want?

> #!/bin/sh
> set -e
> f() {
>       echo foo
>       false
>       echo bar
> }
> f
> [ $? ] || echo baz
> echo buzz

I'm not the original poster, but it does not achieve what I would
expect, which is

foo
baz
buzz

That is, I would expect/want -e to cause the function to return showing
failure.  Instead, it either does nothing or takes down the whole
shell.

This does achieve it, not surprisingly, but it's an ugly kludge; I
would say that neither the nested sh nor the nested set -e should be
necessary:

set -e
f() {
sh -c '
        set -e
        echo "foo $-"
        false
        echo bar
'
}
f || echo baz
echo buzz

/~\ The ASCII                             Mouse
\ / Ribbon Campaign
 X  Against HTML                [email protected]
/ \ Email!           7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B

Reply via email to