Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: substituted command won't inherit stdin in pipeline
- X-seq: zsh-users 24424
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Oğuz <oguzismailuysal@xxxxxxxxx>
- Subject: Re: substituted command won't inherit stdin in pipeline
- Date: Wed, 13 Nov 2019 13:00:23 +0000
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=Mf+dk+CVNK3BtkoDYLtkbM1XtRMelxQop/W4QVhAllo=; b=njHa9RXkefIahlUuJz1tTJYK8k1X+Tg2I0xBlCorIL3j2zrE6yzBlO3MMynKNrvMpa lylbifcyeF9c6NT54QlHfuJCEmcHgaUW/M2wwbt9gBMdIUsoGkqHWTJyaBILO0SKm6qj YGZc7Y4lUz0YSLQYVyFpaaTiI2MrlHm84b686jPQvvs0/eMSR3J12vxjO4wQdEMFK6Sc hLJH17WvvgBz9H7jXXTUmyuQXA89nqtdRR9zVFMDzjHwUNcAzManqY6cgyf4WDPZlrr/ nr3zUS3x+FLU6ggJJAwO8an5ecOVB3YBow1/4/RBv31Hj8pqrWGTCkEoR2FfUP17Djxx GchA==
- In-reply-to: <CAH7i3Lo57yAd==m7zF+8mtETqYDDSptmdzxF-2t_pu42fe9ztQ__41421.1000244663$1573638841$gmane$org@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mail-followup-to: Oğuz <oguzismailuysal@xxxxxxxxx>, zsh-users@xxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author