From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1392 invoked by alias); 30 Aug 2015 03:06:20 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36330 Received: (qmail 2878 invoked from network); 30 Aug 2015 03:06:19 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=TeG1WLVGBayrIWsG3JQpuY7pnXtDbCusZ/+4W4fIQEk=; b=IPuQNtH+b889/4KtEH/OhN9j8Uy4MHj/pOtqaOUC72/URDWaKH3MHwfhRqHsWyDoGB ves/L3/MvzOmkou1mSRJN5Lrhg4oDEtMHHBYrgYBs+OibY011OlX7oxExtjFRuNY/JOm EqrOtWSULEEOkSri0hb38eC7q7vwQn5bYRggb3dihrWIG/8xrGkLUs6lmEnmTNwwKNP9 +BkLbz0GPRGoid9gJOYkFShBLVfEv/swLhv/3eGErynAXr7mXLII2cKsePivYZa6YE/j HjwNmv/z0P4qhp0Z4zg24xM0jgD+MVb5KBxklQWuTLIepxY9OpV1cYHuMTTD1rfoif0U MwLQ== X-Received: by 10.180.72.6 with SMTP id z6mr6054842wiu.57.1440903976227; Sat, 29 Aug 2015 20:06:16 -0700 (PDT) Date: Sun, 30 Aug 2015 05:06:14 +0200 From: Timo Buhrmester To: zsh-workers@zsh.org Subject: [patch] "which"-builtin writes diagnostics to stdout Message-ID: <20150830030614.GB18893@frozen.localdomain> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="d6Gm4EdcadzBjdND" Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) --d6Gm4EdcadzBjdND Content-Type: text/plain; charset=utf-8 Content-Disposition: inline When invoking the `which` builtin for something that does not exist, like: | % which doesnotexist | doesnotexist not found the "doesnotexist not found" message goes to standard output, rather than standard error. This is of course wrong, and particularly nasty in command-substitution, where the diagnostic message might end up in a variable, be given to an external program as an arguemnt or even be be fed through a pipeline. The below (and also attached) patch fixes that. Cheers, Timo Buhrmester ---------8<------------------------------------------------ diff --git a/Src/builtin.c b/Src/builtin.c index 97022ad..774390a 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3578,8 +3578,9 @@ bin_whence(char *nam, char **argv, Options ops, int func) } } if (!informed && (wd || v || csh)) { - zputs(*argv, stdout); - puts(wd ? ": none" : " not found"); + zputs(*argv, stderr); + fputs(wd ? ": none" : " not found", stderr); + fputc('\n', stderr); returnval = 1; } popheap(); @@ -3598,8 +3599,11 @@ bin_whence(char *nam, char **argv, Options ops, int func) informed = 1; } else { /* Not found at all. */ - if (v || csh || wd) - zputs(*argv, stdout), puts(wd ? ": none" : " not found"); + if (v || csh || wd) { + zputs(*argv, stderr); + fputs(wd ? ": none" : " not found", stderr); + fputc('\n', stderr); + } returnval = 1; } } --d6Gm4EdcadzBjdND Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="zsh-which-stderr.patch" diff --git a/Src/builtin.c b/Src/builtin.c index 97022ad..774390a 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3578,8 +3578,9 @@ bin_whence(char *nam, char **argv, Options ops, int func) } } if (!informed && (wd || v || csh)) { - zputs(*argv, stdout); - puts(wd ? ": none" : " not found"); + zputs(*argv, stderr); + fputs(wd ? ": none" : " not found", stderr); + fputc('\n', stderr); returnval = 1; } popheap(); @@ -3598,8 +3599,11 @@ bin_whence(char *nam, char **argv, Options ops, int func) informed = 1; } else { /* Not found at all. */ - if (v || csh || wd) - zputs(*argv, stdout), puts(wd ? ": none" : " not found"); + if (v || csh || wd) { + zputs(*argv, stderr); + fputs(wd ? ": none" : " not found", stderr); + fputc('\n', stderr); + } returnval = 1; } } --d6Gm4EdcadzBjdND--