Re: -e does not work with subscript

2008-01-29 Thread Stepan Koltsov
On 1/29/08, Pierre Gaston <[EMAIL PROTECTED]> wrote:
> On Jan 28, 2008 11:36 PM,  <[EMAIL PROTECTED]> wrote:
> > Configuration Information [Automatically generated, do not change]:
> > Machine: i486
> > OS: linux-gnu
> > Compiler: gcc
> > Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' 
> > -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' 
> > -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
> > -DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2
> > uname output: Linux hilbert 2.6.18-openvz-amd64 #1 SMP Tue Apr 10 19:34:07 
> > MSD 2007 i686 GNU/Linux
> > Machine Type: i486-pc-linux-gnu
> >
> > Bash Version: 3.1
> > Patch Level: 17
> > Release Status: release
> >
> > Description:
> > failed subscript does not cause script to exit, while -e is set
> >
> > Repeat-By:
> >
> > % cat aa.sh
> > set -e
> >
> > (
> > false
> > )
> >
> > echo "unreachable"
> >
> > % bash ./aa.sh
> > unreachable
> > % zsh ./aa.sh
> > zsh: exit 1 zsh ./aa.sh
> >
> > Script aa.sh is expected to exit with error and print nothing. In 
> > bash it prints "unreachable".
> >
> >
> bash exits the subshell you create with ( )  and not the shell:
>
> $ bash -ce '(false;echo foo);echo bar'
> bar

Bash must exit the shell too. Because

$ bash -ce '(false); echo $?'
1

S.




Re: -e does not work with subscript

2008-01-29 Thread Stepan Koltsov
What is "simple command"?

Is

===
( false ) || false
===

simple? Seems like it is not, however

===
set -e

( false ) || false

echo "end"
===

Prints nothing and exits with error.

S.

On 1/29/08, Pierre Gaston <[EMAIL PROTECTED]> wrote:
> On Jan 29, 2008 10:04 AM, Stepan Koltsov <[EMAIL PROTECTED]> wrote:
> >
> > Bash must exit the shell too. Because
> >
> > $ bash -ce '(false); echo $?'
> > 1
> >
> > S.
> >
>
> (false) is a compound command, the bash exits with set -e only if a
> simple command exits with false
>




Re: -e does not work with subscript

2008-01-29 Thread Stepan Koltsov
BTW, my use case for "(false)" is:

===
set -e
( cd some-dir && make )
( cd other-dir && ./build.sh )
( cd third-dir && ant )
===

Most readers (and writers) expect script to fail if "make" failed. So
I think that outer bash should exit with error on "(false)" :-)

Of course, script can be rewritten as

===
( cd some-dir && make ) || false
===

S.

On 1/29/08, Pierre Gaston <[EMAIL PROTECTED]> wrote:
> On Jan 29, 2008 8:09 PM, Stepan Koltsov <[EMAIL PROTECTED]> wrote:
> > What is "simple command"?
> >
> > Is
> >
> > ===
> > ( false ) || false
> > ===
> >
> > simple? Seems like it is not, however
> >
> > ===
> > set -e
> >
> > ( false ) || false
> >
> > echo "end"
> > ===
> >
> > Prints nothing and exits with error.
>
> Indeed according to man bash, this is a list It is perhaps possible to
> consider that the last false is executed as a simple
> command but I think the documentation of set -e could perhaps be made
> more clear about what happens when
> the last command of a list exits with non 0.
>
> I understand why it is implemented this way, so that any non processed
> error exits the shell.
>
> The shells seems to disagree on what (false) should do (ksh and zsh
> exit the shell, dash and bash only the subshell.
> They also seems to disagree on what ! true should do ( zsh exits, bash
> dash and ksh don't)
>




Re: -e does not work with subscript

2008-01-29 Thread Stepan Koltsov
On 1/30/08, Bob Proulx <[EMAIL PROTECTED]> wrote:
> Stepan Koltsov wrote:
> > set -e
> > ( cd some-dir && ./build.sh )
> > ...
> > Most readers (and writers) expect script to fail if "./build.sh" failed. So
> > I think that outer bash should exit with error on "(false)" :-)
> > Of course, script can be rewritten as
> > ( cd some-dir && ./build.sh ) || false
>
> Of course the script can also be written as:
>
>   make -C some-dir

-C flag of make is the reason while such strange behavior of bash is
not well known ;-)

S.