Re: Behaviour of eval in sh(1) and ksh(1) in AND-OR list with set -e

2019-06-06 Thread Christian Weisgerber
On 2019-06-05, Andreas Kusalananda Kähäri  wrote:

> When running under set -e, why does
> eval false || echo ok
> terminate the script with the execution of eval?

I think that's a bug.

> then why does the below behave differently?
> eval ! true || echo ok

That's actually the documented, POSIX-specified behavior.  Somewhat
bizarrely, ! disables errexit.  The eval doesn't matter here.

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Behaviour of eval in sh(1) and ksh(1) in AND-OR list with set -e

2019-06-06 Thread Andreas Kusalananda Kähäri
On Wed, Jun 05, 2019 at 08:05:48PM +0200, Andreas Kusalananda Kähäri wrote:
> When running under set -e, why does
> 
> eval false || echo ok

Just to clarify:

OpenBSD's sh(1) and ksh(1) make it impossible to run code like

set -e
if eval "$string"; then
echo ok
else
echo not ok
fi

where "$string" is a piece of code that returns a non-zero exit status.
This script would not output anything with string=false, for example,
even though the eval occurs as a test within a conditional statement.


> 
> terminate the script with the execution of eval?  As far as I know, the
> OpenBSD sh(1) and ksh(1) shells are the only ones doing that.
> 
> If we take termination of the script as a given in the above scenario
> (even if it feel a bit odd since it's in an AND-OR list), then why does
> the below behave differently?
> 
> eval ! true || echo ok
> 
> This would not terminate the shell regardless of set -e or not.
> 
> Is that a bug or is it a different interpretation of the standard?
> 
> 
> 
> -- 
> Kusalananda
> Sweden

-- 
Kusalananda
Sweden



Behaviour of eval in sh(1) and ksh(1) in AND-OR list with set -e

2019-06-05 Thread Andreas Kusalananda Kähäri
When running under set -e, why does

eval false || echo ok

terminate the script with the execution of eval?  As far as I know, the
OpenBSD sh(1) and ksh(1) shells are the only ones doing that.

If we take termination of the script as a given in the above scenario
(even if it feel a bit odd since it's in an AND-OR list), then why does
the below behave differently?

eval ! true || echo ok

This would not terminate the shell regardless of set -e or not.

Is that a bug or is it a different interpretation of the standard?



-- 
Kusalananda
Sweden