Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: capture stderr in command substitution
- X-seq: zsh-users 26412
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: capture stderr in command substitution
- Date: Mon, 25 Jan 2021 12:38:00 +0000
- Archived-at: <https://zsh.org/users/26412>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-01/20210125123800.5vn5zvtn5sho2rim%40chazelas.org>
- In-reply-to: <1eb9835c-3911-d4ea-6456-d9ad52ceffea@eastlink.ca>
- List-id: <zsh-users.zsh.org>
- Mail-followup-to: Ray Andrews <rayandrews@xxxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxx>
- References: <1eb9835c-3911-d4ea-6456-d9ad52ceffea@eastlink.ca>
2021-01-24 11:45:31 -0800, Ray Andrews:
> $ var=$(command)
>
> ... but $var doesn't pick up errors. Can it be forced?
[...]
var=$(cmd>&2)
like in any Korn/POSIX-like shell.
To capture only stdout:
{ var=$(cmd 2>&1 >&3 3>&-); } 3>&1
That is we need to redirect cmd's stdout back to what it was
originally (after having redirected cmd's stderr to the pipe),
using that extra fd 3 temporarily.
That's also standard sh syntax.
--
Stephane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author