zsh-users
 help / color / mirror / code / Atom feed
From: Matt Zagrabelny <mzagrabe@d.umn.edu>
To: zsh-users@zsh.org
Subject: inconsistency between bash and zsh subshells
Date: Mon, 23 May 2022 11:55:09 -0500	[thread overview]
Message-ID: <CAOLfK3XuyVFK16yxjgFCYRbtEYHJ7m5_XmxfsrmAHi7GYdt3Lw@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2022-05-23 16:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-23 16:55 Matt Zagrabelny [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOLfK3XuyVFK16yxjgFCYRbtEYHJ7m5_XmxfsrmAHi7GYdt3Lw@mail.gmail.com \
    --to=mzagrabe@d.umn.edu \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).