Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Saving error return code in a pipeline

On Thu, Jun 30, 2005 at 11:33:07AM +0200, DervishD wrote:
>     Hi all :)
>     Maybe I'm asking for something impossible, or maybe I'm just dumb
> enough to not see the obvious solution...
>     I have a script which returns an error code, but it outputs a lot
> of info, so I call it like this:
>     script.install |& tee install.log
>     Obviously this 'masks' the return code, but I want to see the
> output even though I'm saving it to a file, so a redirection doesn't
> fit me well. I can use MULTIOS, of course, but I don't want to use it
> for all my commands...
>     Is there any better solution than this?:
>     script.install >(tee install.log) 2>&1

zsh has what it calls mult_ios (mult_ios option which is on by
default) that performs a tee internally when a fd is redirected
several times.

script.install >&1 > install.log 2>&1

Once zsh sees > install.log, it realises that it's the second
time fd 1 is being redirected, so it creates a pipe and a
background process that reads from that pipe and writes what
it's reading both to your terminal and install.log, then
redirects stdout to it. Then 2>&1 redirects stderr as well to
that pipe.

But you can also do:

script.install |& tee install.log


Messages sorted by: Reverse Date, Date, Thread, Author