From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7360 invoked from network); 4 Apr 2004 11:16:34 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 4 Apr 2004 11:16:33 -0000 Received: (qmail 15561 invoked by alias); 4 Apr 2004 11:16:15 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7319 Received: (qmail 15494 invoked from network); 4 Apr 2004 11:16:15 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 4 Apr 2004 11:16:15 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 4 Apr 2004 11:16:14 -0000 Received: (qmail 7335 invoked from network); 4 Apr 2004 11:16:14 -0000 Received: from madrid10.amenworld.com (62.193.203.32) by a.mx.sunsite.dk with SMTP; 4 Apr 2004 11:16:11 -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 i34BG6R27120; Sun, 4 Apr 2004 13:16:06 +0200 Received: from raul@pleyades.net by DervishD.pleyades.net with local (Exim MTA 2.05) id <1BA5br-0007Ga-00>; Sun, 4 Apr 2004 13:16:15 +0200 Date: Sun, 4 Apr 2004 13:16:15 +0200 From: DervishD To: Bart Schaefer Cc: Zsh Users Subject: Re: Honoring a command Message-ID: <20040404111615.GI27014@DervishD> Mail-Followup-To: Bart Schaefer , Zsh Users References: <20040401170312.GA25965@DervishD> <1040403214330.ZM15892@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: <1040403214330.ZM15892@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: > } verbosely_do "Doing whatever command" whatever.command \ > } || { print "Message" >&2; return 1;} > If you have access to the "initscripts" package, you might take a look > at /etc/rc.d/init.d/functions -- particularly the "action" function > that is defined in that file. It does pretty much exactly what your > "verbosely_do" is meant to do (with the addition of wrapping the call > in something called "initlog" which makes syslog entries for the > command, but you can take that out). I don't have that package (well, I've took a look at the initscripts package for Debian, but I think you were talking about the RPM one) > I'd also note that both "action" and "verbosely_do" are assuming that > whatever.command does not produce any standard output of its own, or > else that it's been redirected away somewhere (which is part of what > "initlog" does, I think). Yes, in all my shell functions the command does not spit anything through stdout (or has it redirected as well). That's the reason of the '2>' in my examples: I really don't care about stdout because it is handled, but stderr is not. > Given that the command itself produces no output, you might consider > something like this: Bart, you're a genius :)) This solution is simpler, more powerful and flexible since it doesn't pass the command as a parameter, shorter, easier to understand, does not mess a lot with AND lists or OR lists, etc... The number of beers I owe you is growing dangerously ;) > verbosely_watch() { > emulate -L zsh > local output > print -u2 -n ${(r:WIDTH:)1} > if read output > then > print -u2 $output > else > print -u2 '[ok]' > fi > } > > TRAPZERR() { print '[fail]' } > { whatever.command } 2>/dev/null | verbosely_watch "Doing whatever" I'm going to change it a bit, for not using TRAPZERR: I use it for other purpose in my scripts, although that doesn't seem to work :( (see below) verbosely_watch() { emulate -L zsh local output print -u2 -n ${(r:WIDTH:)1} if read output then print -u2 '[fail]' print $output else print -u2 '[ok]' fi } And after that, I'm going to use it as: { whatever.command 2> /dev/null || print "Error message"} \ | verbosely_watch "Doing whatever" I have the following alias, called 'scriptinit', which is called in all my scripts: alias scriptinit=$'emulate -L zsh ; trap \'return $LINENO\' ZERR' That way, anytime a script fails, its return code tells me the line the failure took place, and I can have silent scripts for some tasks, which still give information about what caused the error (if any). The problem is that it doesn't work with the above usage of verbosely_watch, because the trap is never run due to the OR list. I must replace: { whatever.command 2> /dev/null || print "Error message"} by: { whatever.command 2> /dev/null || print "Error message";false} for my generic trap to work :(, but then 'verbosely_watch' has no purpose at all! 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? Thanks a lot Bart, as always. Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 http://www.pleyades.net & http://raul.pleyades.net/