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

Re: command substitution: zsh waits until command exits



On Dec 4,  2:42am, Vincent Lefevre wrote:
}
} Now, if I understand correctly,
} 
}   $(false) && echo true
} 
} shouldn't output anything because before the &&, there's no command
} and the command substitution has a non-zero exit status.

I would have expected this to produce a shell error of some kind as
there's no command at all to the left of the "&&".  Given that it
does not, I'd say not using the exit status of $(false) is a bug.

I suspect that what's happening is that zsh is losing the exit status
on its way from step 2 to step 4 of the expansion sequence I quoted
previously.  There is no exit status from expanding the non-existent
parameter assignment expressions, so 0 is returned.

This works (i.e., prints nothing and returns 1):

    TRUE=$(false) && echo true

While we're on the subject of empty command words ...

    if ; then echo ok; fi 

... does not produce a syntax error in zsh and also prints "ok".  It
may be there's a relationship there.



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