zsh-users
 help / color / mirror / code / Atom feed
* inconsistency between bash and zsh subshells
@ 2022-05-23 16:55 Matt Zagrabelny
  2022-05-23 17:01 ` Mikael Magnusson
  2022-05-23 17:04 ` Dominik Vogt
  0 siblings, 2 replies; 6+ messages in thread
From: Matt Zagrabelny @ 2022-05-23 16:55 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1014 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 1299 bytes --]

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

end of thread, other threads:[~2022-05-23 17:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-23 16:55 inconsistency between bash and zsh subshells Matt Zagrabelny
2022-05-23 17:01 ` Mikael Magnusson
2022-05-23 17:26   ` Matt Zagrabelny
2022-05-23 17:31     ` Mikael Magnusson
2022-05-23 17:51       ` Matt Zagrabelny
2022-05-23 17:04 ` Dominik Vogt

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).