1

This is zsh -f:

Fereidoons-MacBook-Pro% local a=$(jaja) && echo bad
zsh: command not found: jaja
bad
Fereidoons-MacBook-Pro% a=$(jaja) && echo bad
zsh: command not found: jaja
Fereidoons-MacBook-Pro%

Why is local messing up error handling?

1 Answer 1

3

From the zsh manual regarding the typeset builtin (which local is a special case of):

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"

In your case:

$ unset a
$ local a=$(jaja) && echo bad
zsh: command not found: jaja
bad
$ unset a
$ local a && a=$(jaja) && echo bad
zsh: command not found: jaja

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.