Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: capturing stderr to variable.
- X-seq: zsh-users 20954
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: capturing stderr to variable.
- Date: Sat, 14 Nov 2015 00:01:01 -0800
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern_com.20150623.gappssmtp.com; s=20150623; h=from:message-id:date:in-reply-to:comments:references:to:subject :mime-version:content-type; bh=LSi9pzVpQTSxcWJ6bksKHZTwi0MHzUBcm55xfsUkSzA=; b=kySVRqxdq2lv78R5voR+cpHD8Cx6AQJYKJoo/zgHnETqNQhDfUt2DJk+SCFO631v3F fISjYKxzOF7qgOr8u7qngLbc6OroD42hUjsZ+2g1xxfxL8rQIgW1YPv61rh9WLsmMhcf n4dd4cXPGsKrW90JQlqSF1PO7PCcInI6NeNKrawTXlXRjysFmOVRFWsQJEYMEK2WuNNd VeivqiYTN5WzildrmoLf79YqAfQzdsWUm3Yo2GkeRaweZE1MaGX3H5AyT2Jjr9M1Wcuy 5m3iVGo6jsMwKuadanK3LHmUSyxPC3nSYuw0xRS01VeUQUc/rmlFhU1Ah54Sn7Q6uz+K L8Fw==
- In-reply-to: <CAHYJk3TL6oo4N1+XPr1VsHNThf7pn4SL+2vfsWmM2z6Ttv9T2g@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>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <5646B5F8.3090702@eastlink.ca> <CAHYJk3TL6oo4N1+XPr1VsHNThf7pn4SL+2vfsWmM2z6Ttv9T2g@mail.gmail.com>
On Nov 14, 7:56am, Mikael Magnusson wrote:
}
} On Sat, Nov 14, 2015 at 5:18 AM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
} >
} > 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.
}
} foo 2> >(bar)
That doesn't really help very much, though, because >(bar) runs in a
separate process so the original shell can't do anything interesting
with the captured output.
The shell language doesn't define a digit preceding a "|" symbol as a
redirection because "|" separates commands whereas ">" modifies the
single current command. The difference makes more sense if you are
aware that redirections can appear anywhere:
% >file echo this goes to file
% echo this >>file also goes to file
Whereas "|" ends the command and begins the next.
So, pipes work only on stdout, and to redirect stderr to a pipe you
must first use 2>&1 to copy stderr to stdout ... which means even if
you think it's unclear, you must first separately redirect stdout in
order to pipe only stderr.
E.g.
{ highlight ... >/dev/tty } 2>&1 | read highlight_err
# now $highlight_err has the first line of stderr
# (this does not work in most shells other than zsh)
Note that without the braces, 2>&1 combines stdout and stderr so
both go to /dev/tty and "read" either has no input or reads from
the terminal (depending on whether the "multios" option is set).
--
Barton E. Schaefer
Messages sorted by:
Reverse Date,
Date,
Thread,
Author