[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash 4, subshells and ERR

From: Stephane CHAZELAS
Subject: Re: bash 4, subshells and ERR
Date: Wed, 08 Dec 2010 15:48:15 -0000
User-agent: slrn/pre1.0.0-18 (Linux)

2010-05-13, 02:05(-07), Ian Fitchet:
>  ERR is notionally triggered when a simple command fails.  Subshells
> are both compound commands and do not inherit ERR.  This is what I
> expect (read: am used to):
> 3.2.0% trap 'echo SIGERR' ERR
> 3.2.0% ( false; )
> 3.2.0%
>  However, now I see:
> 4.1.0% trap 'echo SIGERR' ERR
> 4.1.0% ( false; )
> 4.1.0%
>  I'm not saying it's a bad thing only that it's different and not
> documented.

Note that it's the compound command that triggers the "ERR", not
"false". In zsh, you'd get 2 ERRs, one for "false" and one for
(false;), both of which exit with a non-zero status.

> j.  The [[ and (( commands are now subject to the setting of `set -e'
> and the
>     ERR trap.
>  which made me wonder if something had changed regard compound
> commands across the piece.
>  (( i=0 )) now triggers the ERR trap.  That (( returned non-zero when
> the expression evaluated to zero always struck me as a feature but as
> a compound command it never triggered ERR.  Now it might become
> inconvenient! :-)

That was the same behavior in the bourne shell.

expr would return a non-zero exit status when its expression
resolves to 0, which would trigger on "set -e".

Personally, I wouldn't touch "set -e" with a barge pole.

Note that pdksh, mksh and zsh behave like the new bash. Only
ksh93's ((0)) doesn't trigger "set -e".


reply via email to

[Prev in Thread] Current Thread [Next in Thread]