tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: set -e again
On Wed, Jan 14, 2026 at 01:18:47AM +0000, David Holland wrote:
> I discovered the following today.
>
> This:
> set -e
> f() {
> echo foo
> false
> echo bar
> }
> f
>
> as one might expect, prints "foo" and exits.
>
> However, this:
> set -e
> f() {
> echo foo
> false
> echo bar
> }
> f || echo baz
> echo buzz
>
> prints "foo", "bar", "buzz", and continues. Furthermore, all the
> shells I have in easy reach agree on it.
>
> This seems wrong - the exit status of the f is guarded, but the false
> is not. But also, the fact that everybody agrees makes me think it's
> probably the agreed result of the last round of POSIX wrangling over
> the -e definition some years back.
>
> Is this intended, and is there a way to get the user's intended
> behavior of exit on unchecked failure back? (E.g. is there a different
> set to get functions to return on unchecked failure that might cover
> this?)
Does this achieve what you want?
#!/bin/sh
set -e
f() {
echo foo
false
echo bar
}
f
[ $? ] || echo baz
echo buzz
Home |
Main Index |
Thread Index |
Old Index