From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 359759a4 for ; Wed, 13 Nov 2019 13:01:12 +0000 (UTC) Received: (qmail 28988 invoked by alias); 13 Nov 2019 13:01:05 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 24424 Received: (qmail 19138 invoked by uid 1010); 13 Nov 2019 13:01:04 -0000 X-Qmail-Scanner-Diagnostics: from mail-wr1-f50.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.0/25628. spamassassin: 3.4.2. Clear:RC:0(209.85.221.50):SA:0(-2.0/5.0):. Processed in 4.409257 secs); 13 Nov 2019 13:01:04 -0000 X-Envelope-From: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.221.50 as permitted sender) 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state: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=h4V+UsY2xCKFQGCDiFlyPcj61XD739VkZhU63b1ne9vfhmRYc5id5K9+mCgDqoaY9I VJskXtGcwWqM67jeWCsoMP3ThPzA/aOxSS0nk6gIU05vLPzsxzQ/FB3DB7AcvvdArcXM weUMMSS7Htw22nImK+tvO0Bw6Y0d73nFYQ37ZBt+YPkcSxWBm7TY0MdJmucEdMqaUh/F tBe6uEYpzRWbS+m6fPpYJSRNTaot3EVRDEZqaa9v/mTcpHyraWV+RNB18fR6YovqL/PO KF5doOig2SmfI6tZJngUnj659/shlmnU/WuDE74XTLvNN0DDnDWgncqScuNotTeFcpNO ONNQ== X-Gm-Message-State: APjAAAW1MHcVabxs+bxBTk3HYiaBgcc2nOLaXjfzNknLTMkhLSwKxV2V nkYbCYAVKCkESbUMn7A0pHRLZ0JQMGk= X-Google-Smtp-Source: APXvYqxw28rPq5Gq1Q+GsMyS4Q5xpAK7Y5BlOlHEDcMfjHBZBBjzJbqRqHXMSQb30MPhhqs7rTDlvw== X-Received: by 2002:adf:eb8d:: with SMTP id t13mr2630846wrn.321.1573650025930; Wed, 13 Nov 2019 05:00:25 -0800 (PST) Date: Wed, 13 Nov 2019 13:00:23 +0000 From: Stephane Chazelas To: =?utf-8?B?T8SfdXo=?= Cc: zsh-users@zsh.org Subject: Re: substituted command won't inherit stdin in pipeline Message-ID: <20191113130023.n7lgi2vov44kkjfl@chaz.gmail.com> Mail-Followup-To: =?utf-8?B?T8SfdXo=?= , zsh-users@zsh.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20171215 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