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

inconsistency between bash and zsh subshells



Greetings zsh-users,

I'm using zsh 5.8.1 (Debian).

I am seeing inconsistent behavior between using a subshell in the branch of a conditional in bash and zsh.

zsh:

zsh$ rm -f /tmp/FOO
zsh$ ls /tmp/FOO 2> /dev/null || echo "no /tmp/FOO"
no /tmp/FOO
zsh$ echo | while read LINE; do IP=$(echo $LINE | cut -d ' ' -f 1); if [ -n "$IP" ]; then echo FOO; FOO=$(touch /tmp/FOO); else echo BAR; fi; done; ls /tmp/FOO 2> /dev/null || echo "no /tmp/FOO"
BAR
/tmp/FOO

Why does the subshell in zsh get executed even though the conditional branch is not? That is, the "touch"-ing of /tmp/FOO.


bash:

bash$ rm -f /tmp/FOO
bash$ ls /tmp/FOO 2> /dev/null || echo "no /tmp/FOO"
no /tmp/FOO
bash$ echo | while read LINE; do IP=$(echo $LINE | cut -d ' ' -f 1); if [ -n "$IP" ]; then echo FOO; FOO=$(touch /tmp/FOO); else echo BAR; fi; done; ls /tmp/FOO 2> /dev/null || echo "no /tmp/FOO"
BAR
no /tmp/FOO

The bash output is what I would expect zsh to execute/output as well.

Thanks for helping me understand this.

Cheers!

-m


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