>Synopsis: ksh: failing eval stops execution even when in OR-list
>Category: user
>Environment:
System : OpenBSD 6.6
Details : OpenBSD 6.6 (GENERIC.MP) #3: Thu Nov 21 03:20:01 MST 2019
[email protected]:/usr/src/sys/arch/amd64/compile/GENERIC.MP
Architecture: OpenBSD.amd64
Machine : amd64
>Description:
When under "set -e", using "eval" in an OR-list, a failure during evaluation
of the eval string will stop the shell, and not trigger the OR-list:
set -e
eval false || true
echo pass
Output of this script on OpenBSD:
$ sh sete.sh ; echo $?
1
Output with various other shells:
% ksh93 sete.sh
pass
% dash sete.sh
pass
% posh sete.sh
pass
% yash sete.sh
pass
% mksh sete.sh
pass
% bash sete.sh
pass
% zsh sete.sh
pass
% busybox sh sete.sh
pass
I think this is in violation of the POSIX 2008 specification:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#set
> The -e setting shall be ignored when executing the compound list
> following the while, until, if, or elif reserved word, a pipeline
> beginning with the ! reserved word, or any command of an AND-OR list
> other than the last.
>How-To-Repeat:
Running this script as a reproducer:
set -e
eval false || true
echo pass
>Fix:
As a workaround: eval "false || true" || true
Thanks,
--
Leah Neukirchen <[email protected]> https://leahneukirchen.org/