Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
	T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=mime-version:date:message-id:subject:from:to;
        bh=Al2lnsAWOQzBP+NFpYR3nMsYe3vGaSadrxC7AbExgwk=;
        b=p61J6wqZq4gguajDO0LO9MpPhZ2IWdHTpw5I2zGrzYPaA1cQlD/vA/+/x9E7ZMwYty
         Np7EptTQFn5U11r7yCjmSxt5+EI/4GqnoqsU1n0qB2QtDwiEcNCPXm/ysmSGbwKM/I1k
         f2YErxbjw53x4MBYNcGzblsQ1aorCj6F0xIdy8r/IJpAW5b+wg5ANxZKFE0x2IQnKTQ5
         wVEARspULNUAxSKmZPzvST5nKEHUWLEC3n+/rX1M5i+AnJbkPNCmtAl6SIkGlPSvjvG1
         kyyHaxPvpoY/Eq9Uds2UjckdGIbjXoPjg/UnHAZQZ8fxCt6sqBL7jscltE0WfR2HkCcY
         kn1A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:date:message-id:subject:from:to;
        bh=Al2lnsAWOQzBP+NFpYR3nMsYe3vGaSadrxC7AbExgwk=;
        b=XayXVA5ort9iiR287R3QSnb0cXfcTju2zL32C2080SRPvqCdjBGcsl0+EEtXGp1c3m
         +dl81DsDtjvF4VK2/xqvVKthTxyBCUsNk1BYdtb/QfR3MEXmZ4o2adGwoz1FrHDRfMFd
         GAoj2ggUXfek9dkL7PCzypCWORlqG0n4uqxVOpTFQwgtbSafQWQe218WYQolHlvQOhlN
         Wj00Ie2qd5KineF0hWfn2LflbDevZBfX8Jw+DfaIknTRnircvw2bNLHKBb8Z533Q3Jjy
         4c5hh7TpQj2pgIH3j2PiquRdjNj6QIIqevOHkxXRoyEmPRVMc/PkFF124bHj/rJufJxJ
         eRig==
X-Gm-Message-State: AD7BkJKmWyUISxKd3tLykCtqPGsTa0eWkGLyTk2On9wpNkBBo74v3H7Dzm9HmDKV0+hjKopDN6ZfIRFl5glq7Q==
MIME-Version: 1.0
X-Received: by 10.31.180.85 with SMTP id d82mr13985047vkf.83.1457284932160;
 Sun, 06 Mar 2016 09:22:12 -0800 (PST)
Date: Sun, 6 Mar 2016 12:22:12 -0500
Message-ID: <CAFvQaj4EoLxrogEUHu02vpX9qZ77SvhuByKCZMdvJew3bNM+=w@mail.gmail.com>
Subject: Possible redirection bug in zsh 5x
From: Kynn Jones <kynnjo@gmail.com>
To: zsh-workers@zsh.org
Content-Type: text/plain; charset=UTF-8
X-Seq: zsh-workers 38101

(NB: I originally posted something very close to the message below as
a unix.stackexchange.com question, but it got no answers.  I took this
as confirmation that this may indeed be a bug.)

---

The following command produces different outputs in zsh v. 4.x and 5.x:

    {
      (
        printf "X\nY\n"
        printf "WARNING: foo\nWARNING: bar\n" >&2
        printf "1\n2\n"
      ) 2>&1 >&3 | grep -v foo >&2
    } 3>&1

(This code is supposed to illustrate how to selectively suppress some
of the output sent to stderr by a program; in this case, the warning
`foo` is being suppressed selectively, while the warning `bar` is
allowed to go through; note that in the end, `stderr` and `stdout`
streams remain separate.)

On v 4.x the output I see at the terminal is as desired/expected:

    X
    Y
    1
    2
    WARNING: bar

(You may see a different ordering of the `WARNING: bar` line relative
to the other ones.)

[NB: as pointed out in a comment to my unix.stackexchange.com
question, both bash and dash also produce the output shown above.]

On v 5.0.7 (Debian) and 5.1.1 (Darwin), however, what I see at the
terminal is this:

    X
    Y
    1
    2
    WARNING: bar
    X
    Y
    1
    2

IOW, the lines that should be sent to `stdout` appear twice.

I figure there are three possibilities:

  1. this is a bug in v. 5.x (in which case my question is: is there a
workaround?)
  2. I have not properly configured my v. 5.x zsh (in which case my
question is: how should I configure my v. 5.x zsh to get the desired
behavior?);
  3. [very unlikely, in light of the results for bash and dash] there
is a bug in v. 4.x, but not in v. 5.x, that masked a bug in my code
(in which case my question is: how could I fix my code to get the
desired behavior in v 5.x?)

Thank you in advance,

kj

