From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19089 invoked from network); 30 Jun 2005 12:01:25 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 30 Jun 2005 12:01:25 -0000 Received: (qmail 80078 invoked from network); 30 Jun 2005 12:01:19 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 30 Jun 2005 12:01:19 -0000 Received: (qmail 4263 invoked by alias); 30 Jun 2005 12:01:11 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9002 Received: (qmail 4254 invoked from network); 30 Jun 2005 12:01:10 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 30 Jun 2005 12:01:10 -0000 Received: (qmail 78907 invoked from network); 30 Jun 2005 12:01:10 -0000 Received: from caly80.spider.com (HELO bifrost.spider.com) (194.217.109.12) by a.mx.sunsite.dk with SMTP; 30 Jun 2005 12:01:06 -0000 Received: from no.name.available by bifrost.spider.com via smtpd (for [130.225.247.86]) with SMTP; 30 Jun 2005 12:01:06 UT Received: from heimdall-dmz.spider.com (mailhub.spider.com [212.240.99.13]) by caly80.spider.com (Postfix) with SMTP id 10B386F8D for ; Thu, 30 Jun 2005 13:01:00 +0100 (BST) Received: from mailhub.spider.com by heimdall-dmz.spider.com via smtpd (for [172.16.254.22]) with SMTP; 30 Jun 2005 12:01:00 UT Received: from localhost (duey.spider.com [212.240.99.128]) by batistuta.spider.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id N84DS9M7; Thu, 30 Jun 2005 12:56:46 +0100 Date: Thu, 30 Jun 2005 13:00:58 +0100 From: Stephane Chazelas To: Zsh Users Subject: Re: Saving error return code in a pipeline Message-ID: <20050630120058.GA28910@artesyncp.com> Mail-Followup-To: Zsh Users References: <20050630093307.GA23323@DervishD> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050630093307.GA23323@DervishD> User-Agent: Mutt/1.5.7i X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 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 script_exit_status=$pipestatus[1] -- Stephane