zsh-users
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Oğuz <oguzismailuysal@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: substituted command won't inherit stdin in pipeline
Date: Wed, 13 Nov 2019 13:00:23 +0000	[thread overview]
Message-ID: <20191113130023.n7lgi2vov44kkjfl@chaz.gmail.com> (raw)
In-Reply-To: <CAH7i3Lo57yAd==m7zF+8mtETqYDDSptmdzxF-2t_pu42fe9ztQ__41421.1000244663$1573638841$gmane$org@mail.gmail.com>

2019-11-13 12:52:20 +0300, Oğuz:
> On all sh implementations I have, this command
> 
>     echo foo | echo "$(cat)"
> 
> prints 'foo', except for zsh, it hangs instead. From that I gather cat
> doesn't inherit echo's stdin, and it waits for input.
[...]

Not exactly what happens in that the expansions in the arguments
of the commands in the pipeline are performed in the parent,
from left to right, not in the processes that run the
individualy pipe components (also note that the right-most pipe
component is run in the current shell anyway, like in ksh93,
unlike in bash).

So:

   echo bar | { echo foo | echo "$(cat)"; }

would output "bar".

And:

   n=0; echo $((++n)) | echo $((++n))

outputs 2.

There are advantages and drawbacks in the way zsh works, but
it's too late to change it.

Here, to be compatible with the bash and zsh approaches, you'd
do:

   echo foo | (echo "$(cat)")

Or to get the same as bash -O lastpipe:

   n=0; echo foo | { echo "$((++n))$(cat)"; }; echo "$n"

-- 
Stephane

       reply	other threads:[~2019-11-13 13:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAH7i3Lo57yAd==m7zF+8mtETqYDDSptmdzxF-2t_pu42fe9ztQ__41421.1000244663$1573638841$gmane$org@mail.gmail.com>
2019-11-13 13:00 ` Stephane Chazelas [this message]
2019-11-13 13:30   ` Oğuz
     [not found]   ` <CAH7i3LrwD4G0CJ3WvdWZsp5u-cSTQoGomSf6HHF1XG8NnA89Vw__34634.6754276723$1573691143$gmane$org@mail.gmail.com>
2019-11-14  7:57     ` Stephane Chazelas
2019-11-14  8:43       ` Oğuz
2019-11-14  9:35         ` Peter Stephenson
2019-11-14  9:38           ` Roman Perepelitsa
2019-11-13  9:52 Oğuz

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=20191113130023.n7lgi2vov44kkjfl@chaz.gmail.com \
    --to=stephane.chazelas@gmail.com \
    --cc=oguzismailuysal@gmail.com \
    --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).