Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: local/non-local and sub shell exit codes



Ok, I have to take it back. Found the following in the manpage (after
discovering, that 'local' is an alias for 'typeset'):

---8<---
Unlike parameter assignment statements, typeset's exit status on an
assignment that involves a command substitution does not reflect the
exit status of the command substitution. Therefore, to test for an error
in a command substitution, separate the declaration of the parameter
from its initialization:
  # WRONG
  typeset var1=$(exit 1) || echo "Trouble with var1"

  # RIGHT
  typeset var1 && var1=$(exit 1) || echo "Trouble with var1"
--->8---

- René

Am 10.06.2018 um 15:18 schrieb René Neumann:
> Hi all,
> 
> I just encountered this strange behavior under zsh-5.5.1:
> 
> % foo=$(false); echo $?
> 1
> % local foo=$(false); echo $?
> 0
> 
> Is this intended? As I'm pretty sure that this behavior is new...
> 
> Best regards,
> René
> 



Messages sorted by: Reverse Date, Date, Thread, Author