zsh-users
 help / color / mirror / code / Atom feed
* Redirecting shell output to a pipe
@ 2009-11-24 14:31 Nadav Har'El
  2009-11-24 18:33 ` Peter Miller
  0 siblings, 1 reply; 10+ messages in thread
From: Nadav Har'El @ 2009-11-24 14:31 UTC (permalink / raw)
  To: zsh-users

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

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.

-- 
Nadav Har'El                        |      Tuesday, Nov 24 2009, 7 Kislev 5770
nyh@math.technion.ac.il             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |"Guests, like fish, begin to smell after
http://nadav.harel.org.il           |three days." -- Benjamin Franklin


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-11-25 14:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-24 14:31 Redirecting shell output to a pipe Nadav Har'El
2009-11-24 18:33 ` Peter Miller
2009-11-24 18:50   ` Joke de Buhr
2009-11-25  6:48   ` Nadav Har'El
2009-11-25 11:52     ` Joke de Buhr
2009-11-25 13:44       ` Nadav Har'El
2009-11-25 13:51         ` Norman.Azadian
2009-11-25 12:37     ` Peter Stephenson
2009-11-25 14:15       ` Nadav Har'El
2009-11-25 14:34         ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).