[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: set -e in bash 4
From: |
Tobias Poschwatta |
Subject: |
Re: set -e in bash 4 |
Date: |
Wed, 21 Oct 2009 13:04:53 +0200 |
User-agent: |
Mutt/1.4.2.2i |
On Wed, Oct 21, 2009 at 10:19:52AM +0100, Marc Herbert wrote:
> Tobias Poschwatta a écrit :
> > In the following test case test1.sh, bash 4 behaves differently from
> > bash 3.1. The behaviour of bash 3.1 is what I would expect to be
> > correct. Is this a bug in bash 4 or an intentional change?
>
> Isn't this related to this change?
> http://thread.gmane.org/gmane.comp.shells.bash.bugs/13465
Thanks for the link, but I don't think it is related.
I understand that the presence of || resets errexit for the subshell
in:
$ cat a.sh
set -e
( echo 1; false; echo 2 ) || echo failed
echo done
$ /bin/bash a.sh
1
2
done
To get errexit in the subshell, I tried to enable it inside the
subshell:
$ cat b.sh
( set -e; echo 1; false; echo 2 ) || echo failed
echo done
$ /bin/bash b.sh
1
2
done
But 'set -e' inside the subshell has no effect. So, I tried to replace
|| with a test of $? which finally worked (but only if errexit is
disabled outside the subshell).
$ cat c.sh
( set -e; echo 1; false; echo 2 )
[ $? -eq 0 ] || echo failed
echo done
$ /bin/bash c.sh
1
failed
done
I find this very counterintuitive, and wonder if it's really the
correct behavior.
Thanks,
Tobias