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

* Re: inconsistency between bash and zsh subshells
  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:04 ` Dominik Vogt
  1 sibling, 1 reply; 6+ messages in thread
From: Mikael Magnusson @ 2022-05-23 17:01 UTC (permalink / raw)
  To: Matt Zagrabelny; +Cc: zsh-users

On 5/23/22, Matt Zagrabelny <mzagrabe@d.umn.edu> wrote:
> 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.

You're most likely using a poorly written prompt theme and/or thing
that updates your terminal title. Try disabling that code and try
again if so.

-- 
Mikael Magnusson


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

* Re: inconsistency between bash and zsh subshells
  2022-05-23 16:55 inconsistency between bash and zsh subshells Matt Zagrabelny
  2022-05-23 17:01 ` Mikael Magnusson
@ 2022-05-23 17:04 ` Dominik Vogt
  1 sibling, 0 replies; 6+ messages in thread
From: Dominik Vogt @ 2022-05-23 17:04 UTC (permalink / raw)
  To: zsh-users

On Mon, May 23, 2022 at 11:55:09AM -0500, Matt Zagrabelny wrote:
> 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"

This output cannot have been generated by the above command:

> BAR
> /tmp/FOO     <--- ???

Ciao

Dominik ^_^  ^_^

--

Dominik Vogt


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

* Re: inconsistency between bash and zsh subshells
  2022-05-23 17:01 ` Mikael Magnusson
@ 2022-05-23 17:26   ` Matt Zagrabelny
  2022-05-23 17:31     ` Mikael Magnusson
  0 siblings, 1 reply; 6+ messages in thread
From: Matt Zagrabelny @ 2022-05-23 17:26 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-users

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

On Mon, May 23, 2022 at 12:01 PM Mikael Magnusson <mikachu@gmail.com> wrote:

> On 5/23/22, Matt Zagrabelny <mzagrabe@d.umn.edu> wrote:
>
> > Why does the subshell in zsh get executed even though the conditional
> > branch is not? That is, the "touch"-ing of /tmp/FOO.
>
> You're most likely using a poorly written prompt theme and/or thing
> that updates your terminal title.


Haha. Probably!



> Try disabling that code and try
> again if so.
>

Yup - that was it. I removed my .zshrc and it works as expected.

Thanks for the hint! Time to figure out what poorly written part of my
.zshrc is to blame.

Cheers,

-m

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

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

* Re: inconsistency between bash and zsh subshells
  2022-05-23 17:26   ` Matt Zagrabelny
@ 2022-05-23 17:31     ` Mikael Magnusson
  2022-05-23 17:51       ` Matt Zagrabelny
  0 siblings, 1 reply; 6+ messages in thread
From: Mikael Magnusson @ 2022-05-23 17:31 UTC (permalink / raw)
  To: Matt Zagrabelny; +Cc: zsh-users

On 5/23/22, Matt Zagrabelny <mzagrabe@d.umn.edu> wrote:
> On Mon, May 23, 2022 at 12:01 PM Mikael Magnusson <mikachu@gmail.com>
> wrote:
>
>> On 5/23/22, Matt Zagrabelny <mzagrabe@d.umn.edu> wrote:
>>
>> > Why does the subshell in zsh get executed even though the conditional
>> > branch is not? That is, the "touch"-ing of /tmp/FOO.
>>
>> You're most likely using a poorly written prompt theme and/or thing
>> that updates your terminal title.
>
>
> Haha. Probably!
>
>
>
>> Try disabling that code and try
>> again if so.
>>
>
> Yup - that was it. I removed my .zshrc and it works as expected.
>
> Thanks for the hint! Time to figure out what poorly written part of my
> .zshrc is to blame.

It will probably be something involving print -P and \a or \007 in
something named preexec. If you change $1 in that to \$1 it is more
likely to work, though it's of course hard to say without seeing the
particular code. If you instead remove any setopt printsubst it should
work fine without modifying the preexec function. (only do one of
these changes). Basically what's happening is you're expanding the
string to put in the title twice, resulting in things like $()
actually being executed which is usually not great.

-- 
Mikael Magnusson


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

* Re: inconsistency between bash and zsh subshells
  2022-05-23 17:31     ` Mikael Magnusson
@ 2022-05-23 17:51       ` Matt Zagrabelny
  0 siblings, 0 replies; 6+ messages in thread
From: Matt Zagrabelny @ 2022-05-23 17:51 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: zsh-users

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

On Mon, May 23, 2022 at 12:32 PM Mikael Magnusson <mikachu@gmail.com> wrote:

> On 5/23/22, Matt Zagrabelny <mzagrabe@d.umn.edu> wrote:
> > On Mon, May 23, 2022 at 12:01 PM Mikael Magnusson <mikachu@gmail.com>
> > wrote:
> >
> >> On 5/23/22, Matt Zagrabelny <mzagrabe@d.umn.edu> wrote:
> >>
> >> > Why does the subshell in zsh get executed even though the conditional
> >> > branch is not? That is, the "touch"-ing of /tmp/FOO.
> >>
> >> You're most likely using a poorly written prompt theme and/or thing
> >> that updates your terminal title.
> >
> >
> > Haha. Probably!
> >
> >
> >
> >> Try disabling that code and try
> >> again if so.
> >>
> >
> > Yup - that was it. I removed my .zshrc and it works as expected.
> >
> > Thanks for the hint! Time to figure out what poorly written part of my
> > .zshrc is to blame.
>
> It will probably be something involving print -P and \a or \007 in
> something named preexec. If you change $1 in that to \$1 it is more
> likely to work,


Probably = 100% likely.


> though it's of course hard to say without seeing the
> particular code.


For fun, and full disclosure, here is the code:

preexec () {
    case $TERM in (xterm*|screen*|tmux*|rxvt)
        print -Pn "\e]0;%(!.-=*[ROOT]*=- | .)%n@%m:%y : $1\a"
    esac
}

to which I've changed $1 to \$1 and it fixes the issue.

Thanks for the help, Mikael! It is very appreciated!

-m

[-- Attachment #2: Type: text/html, Size: 2407 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 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).