Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Redirecting shell output to a pipe
- X-seq: zsh-users 14598
- From: Peter Miller <Peter.Miller@xxxxxxx>
- To: "Nadav Har'El" <nyh@xxxxxxxxxxxxxxxxxxx>
- Subject: Re: Redirecting shell output to a pipe
- Date: Tue, 24 Nov 2009 13:33:45 -0500
- Cc: zsh-users@xxxxxxx
- In-reply-to: <20091124143140.GA7612@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- 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: <20091124143140.GA7612@xxxxxxxxxxxxxxxxxxxxxxxxxx>
- Sender: Peter.Miller@xxxxxxx
Nadav Har'El wrote:
> Hi,
>
> If a shell script wants all its output to go to a file, it's easy:
>
> exec >filename 2>&1
>
> Isn't it natural to assume that in the same fashion, you should also
> be able to redirect the scripts output to a pipe? E.g., a very useful
> idiom could have been
>
> exec | tee filename
>
exec |& tee filename
> to redirect stdout both to a file, and to the terminal.
> But unfortunately, the above line does *not* work. Is there a reason why
> it doesn't? Wouldn't this be a useful feature?
>
> By the way, for the curious, there is actually a different solution to this
> need, but it is much more convoluted. The other solution is to write this:
>
> exec 3>&1
> coproc tee /tmp/b >&3
> exec >&p 2>&1
>
> (and perhaps do something, I'm not even sure what, at the end of the script
> to give the tee coprocess enough time to finish outputting before the script
> exits).
>
> Another downside of this solution, besides being extremely complex (99%
> of the zsh users will probably not be able to figure it out), is that
> it takes the only coprocess that zsh gives you, which won't work if your
> code is already using coprocesses.
>
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author