[Nix-dev] Re: eval $buildPhase and exit code in case of syntax error

Eelco Dolstra e.dolstra at tudelft.nl
Mon Oct 20 00:29:47 CEST 2008


Ludovic Courtès wrote:

> Eelco Dolstra <e.dolstra at tudelft.nl>
> writes:
> 
>> BTW, this isn't the only place where bash silently ignores errors (even with
>> "-e" active).  For instance, errors from subshells (e.g. "(cd /foo)") are ignored.
> 
> Really?
> 
>   $ ( cd /foo ) ; echo $?
>   bash: cd: /foo: No such file or directory
>   1

I meant that the calling shell ignores the exitcode of the subshell when -e is
active.  So an error in

  (cd $somedir && tar cf $out/foo.tar bla)

is ignored, while it isn't if you do

  cd $somedir && tar cf $out/foo.tar bla

But this changes the current directory, which is why you want a subshell.  The
workaround is to say

  (cd $somedir && tar cf $out/foo.tar bla) || false

Stricly speaking this isn't a bug, because the bash man-page says that "-e" only
applies to "simple commands" (not subshells).  But it's still counter-intuitive
IMHO.

-- 
Eelco Dolstra | http://www.st.ewi.tudelft.nl/~dolstra/



More information about the nix-dev mailing list