Consider the commands
eval false || echo ok echo also ok
Ordinarily, we'd expect this to execute the
false utility and, since the exit status is non-zero, to then execute
echo ok and
echo also ok.
In all the POSIX-like shells I use (
yash), this is what happens, but things get interesting if we enable
set -e is in effect, OpenBSD's
ksh shells (both derived from
pdksh) will terminate the script when executing the
eval. No other shell does that.
POSIX says that an error in a special built-in utility (such as
eval) should cause the non-interactive shell to terminate. I'm not entirely sure whether executing
false constitutes "an error" (if it was, it would be independent of
set -e being active).
The way to work around this seems to be to put the
eval in a sub shell,
( eval false ) || echo ok echo also ok
The question is whether I'm expected to have to do that in a POSIX-ly correct shell script, or whether it's a bug in OpenBSD's shell? Also, what is meant by "error" in the POSIX text linked to above?
Extra bit of info: The OpenBSD shells will execute the
echo ok both with and without
set -e in the command
eval ! true || echo ok
My original code looked like
set -e if eval "$string"; then echo ok else echo not ok fi
which would not output
not ok with
string=false using the OpenBSD shells (it would terminate), and I wasn't sure it was by design, by mistake or by misunderstanding, or something else.