From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9020 invoked from network); 5 Apr 2004 10:18:07 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 5 Apr 2004 10:18:07 -0000 Received: (qmail 4555 invoked by alias); 5 Apr 2004 10:17:21 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7327 Received: (qmail 4533 invoked from network); 5 Apr 2004 10:17:20 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 5 Apr 2004 10:17:20 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 5 Apr 2004 10:17:20 -0000 Received: (qmail 4402 invoked from network); 5 Apr 2004 10:17:19 -0000 Received: from madrid10.amenworld.com (62.193.203.32) by a.mx.sunsite.dk with SMTP; 5 Apr 2004 10:17:17 -0000 Received: from DervishD.pleyades.net (212.Red-80-35-44.pooles.rima-tde.net [80.35.44.212]) by madrid10.amenworld.com (8.10.2/8.10.2) with ESMTP id i35AHCU01247; Mon, 5 Apr 2004 12:17:13 +0200 Received: from raul@pleyades.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1BAQsw-0005Fo-00>; Mon, 5 Apr 2004 11:59:18 +0200 Date: Mon, 5 Apr 2004 11:59:18 +0200 From: DervishD To: Bart Schaefer Cc: Zsh Users Subject: Re: Honoring a command Message-ID: <20040405095918.GA20195@DervishD> Mail-Followup-To: Bart Schaefer , Zsh Users References: <20040401170312.GA25965@DervishD> <1040403214330.ZM15892@candle.brasslantern.com> <20040404111615.GI27014@DervishD> <1040405010932.ZM22507@candle.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1040405010932.ZM22507@candle.brasslantern.com> User-Agent: Mutt/1.4.2.1i Organization: Pleyades X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, hits=0.0 required=6.0 tests=none autolearn=no version=2.63 X-Spam-Hits: 0.0 Hi Bart :) * Bart Schaefer dixit: > } The number of beers I owe you is growing dangerously ;) > Especially considering that I rarely drink beer. Send me a six-pack of > some unusual Spanish soft drink, or something. ;-} I think the only soft drinks we have in Spain are from abroad, but I'll take a look ;)) > } alias scriptinit=$'emulate -L zsh ; trap \'return $LINENO\' ZERR' > An interesting tidbit I just noticed -- if you read the script with the > "source" or "." commands, $LINENO is reset to 1 when the trap runs, so > you don't get as useful a return value. I know, but I never source that scrips (is there any way to make a script as 'unsourceable' :?). This ZERR thing for returning an error code is not very solid :( I should work in a better one, but I had never the need O:) > } { whatever.command 2> /dev/null || print "Error message";false} > Actually that won't work either, because that _always_ executes "false". > I think you meant > { whatever.command 2> /dev/null || { print "Error message";false } } Yes, I forgot the braces, sorry O:) > } but then 'verbosely_watch' has no purpose at all! > You could write another little function: > verbosely_fail() { > local ret=$? > [[ -p /dev/fd/1 ]] && print "$*" > return ret > } That's nice :) > > Now this works: > > { whatever.command || verbosely_fail "Error message" } 2>/dev/null | > verbosely_watch "Doing whatever" > > If you DON'T pipe to verbosely_watch, then verbosely_fail is silent and the > ZERR trap returns the line number as $?. (Even if you do pipe it, the line > number is stored in $pipestatus[1], which may be useful for other tricks.) > > } I think I'd better use 'scriptinit' only for muted > } scripts and verbosely_watch for the rest, using TRAPZERR for the > } error message. Is that a good idea? > That would work as well, but it means the error message is the same for > every command (unless you re-assign it somehow each time). That's not a problem, I can use a global variable for the message and reassign it before each command is run, instead of redefining TRAPZERR (and obviously I must make TRAPZERR output that variable). Finally I think that the solution I'm going to adopt is the function 'verbosely_watch', TRAPZERR for the error message instead the OR list. I'm afraid that using ZERR to return the line number of the error is only useful for debugging, to know where a bug happened, but for production scripts I think is better to have a reduced and well defined set of error return codes. Thanks a lot for your, as always, invaluable help. Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 http://www.pleyades.net & http://raul.pleyades.net/