zsh-users
 help / color / mirror / code / Atom feed
* local/non-local and sub shell exit codes
@ 2018-06-10 13:18 René Neumann
  2018-06-10 13:34 ` René Neumann
  0 siblings, 1 reply; 3+ messages in thread
From: René Neumann @ 2018-06-10 13:18 UTC (permalink / raw)
  To: Zsh Users

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é


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: local/non-local and sub shell exit codes
  2018-06-10 13:18 local/non-local and sub shell exit codes René Neumann
@ 2018-06-10 13:34 ` René Neumann
  2018-06-10 13:46   ` dana
  0 siblings, 1 reply; 3+ messages in thread
From: René Neumann @ 2018-06-10 13:34 UTC (permalink / raw)
  To: zsh-users

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é
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: local/non-local and sub shell exit codes
  2018-06-10 13:34 ` René Neumann
@ 2018-06-10 13:46   ` dana
  0 siblings, 0 replies; 3+ messages in thread
From: dana @ 2018-06-10 13:46 UTC (permalink / raw)
  To: zsh; +Cc: René Neumann

On 10 Jun 2018, at 08:34, René Neumann <lists@necoro.eu> wrote:
>Ok, I have to take it back. Found the following in the manpage (after
>discovering, that 'local' is an alias for 'typeset'):

FYI, although that note was only added in 2016*, the behaviour is definitely
older than that. That's how it works in bash as well, and shellcheck warns you
about it by default.

* A result of this discussion: http://www.zsh.org/mla/workers/2016/msg00140.html

dana


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-10 13:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-10 13:18 local/non-local and sub shell exit codes René Neumann
2018-06-10 13:34 ` René Neumann
2018-06-10 13:46   ` dana

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).