From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11624 invoked from network); 3 Apr 2004 21:43:51 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 3 Apr 2004 21:43:51 -0000 Received: (qmail 26327 invoked by alias); 3 Apr 2004 21:43:34 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7318 Received: (qmail 26316 invoked from network); 3 Apr 2004 21:43:34 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 3 Apr 2004 21:43:34 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [130.225.247.86] by sunsite.dk (MessageWall 1.0.8) with SMTP; 3 Apr 2004 21:43:34 -0000 Received: (qmail 6152 invoked from network); 3 Apr 2004 21:43:33 -0000 Received: from wbar3.sjo1-4-11-009-147.sjo1.dsl-verizon.net (HELO candle.brasslantern.com) (4.11.9.147) by a.mx.sunsite.dk with SMTP; 3 Apr 2004 21:43:32 -0000 Received: (from schaefer@localhost) by candle.brasslantern.com (8.11.6/8.11.6) id i33LhUE15893 for zsh-users@sunsite.dk; Sat, 3 Apr 2004 13:43:30 -0800 X-Authentication-Warning: candle.brasslantern.com: schaefer set sender to schaefer@closedmail.com using -f From: Bart Schaefer Message-Id: <1040403214330.ZM15892@candle.brasslantern.com> Date: Sat, 3 Apr 2004 21:43:30 +0000 In-Reply-To: <20040401170312.GA25965@DervishD> Comments: In reply to DervishD "Honoring a command" (Apr 1, 7:03pm) References: <20040401170312.GA25965@DervishD> X-Mailer: Z-Mail (5.0.0 30July97) To: Zsh Users Subject: Re: Honoring a command MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Checker-Version: SpamAssassin 2.63 on a.mx.sunsite.dk X-Spam-Level: **** X-Spam-Status: No, hits=4.7 required=6.0 tests=RCVD_IN_DYNABLOCK, RCVD_IN_NJABL,RCVD_IN_NJABL_DIALUP,RCVD_IN_SORBS autolearn=no version=2.63 X-Spam-Hits: 4.7 On Apr 1, 7:03pm, DervishD wrote: } } [...] the question is that I want to modify code like this: } } print -n "Doing whatever command..." >&2 } whatever.command 2> /dev/null || { print " error! Message" >&2; return 1; } } print " done." >&2 } } } to this: } } 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). Something to note about that "action" function is that it folds the failure message into the wrapper function rather than following the wrapper call with an or-command. } The problem I see is: what will happen if the command has } redirections, metacharacters, quotes, variable references, etc.? Unless you quote them, they'll all be processed BEFORE verbosely_do is called, which may or may not do what you want. If you do quote them, then you'll probably need to use eval "$*" inside the verbosely_do function, which of course has it's own set of problems. As far as I can tell, the "action" function I mentioned assumes that there are no redirections and that it's OK for metachars and so on to have been expanded before the call. 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). Given that the command itself produces no output, you might consider something like this: 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" That allows any syntax you like within the { }.