From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15885 invoked by alias); 14 Nov 2015 04:48:09 -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: X-Seq: 20952 Received: (qmail 14002 invoked from network); 14 Nov 2015 04:48:07 -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=-1.9 required=5.0 tests=BAYES_00,T_HDRS_LCASE, T_MANY_HDRS_LCASE autolearn=ham autolearn_force=no version=3.4.0 X-Authority-Analysis: v=2.1 cv=X+5rdgje c=1 sm=1 tr=0 a=2HRJbREI7CNh35z1D4ZSNQ==:117 a=2HRJbREI7CNh35z1D4ZSNQ==:17 a=IkcTkHD0fZMA:10 a=rf-cl79OjC67EFr5fHkA:9 a=QEXdDO2ut3YA:10 Message-id: <5646B5F8.3090702@eastlink.ca> Date: Fri, 13 Nov 2015 20:18:00 -0800 From: Ray Andrews User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-version: 1.0 To: Zsh Users Subject: capturing stderr to variable. Content-type: text/plain; charset=utf-8; format=flowed Content-transfer-encoding: 7bit Gentlemen: 'highlight' seems to have no return value. If you feed it a file who's type it does not recognize, it sends a message to stderr. To create a test for that, I'm doing this: $ highlight $filename 2> /tmp/highlight_err [ -s "/tmp/highlight_err" ] && echo="Highlighting is active, but the file is not recognized." rm /tmp/highlight_err > /dev/null ... which is clumsy. Researching it, I find that there's no simple way to redirect stderr to a variable, or to some other way of capturing the error condition. Suggestions involve things like: ... 2>&4 1>&3; } 2>&1 ) ... which I'd not use anyway for clarity's sake. Any suggestions? I was wondering, since redirection and piping are (I believe) at about the same level of parsing, one might suppose that " ... 2| " would be legal. That is to say that we could sent stderr to a command as well as to a file.