From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19971 invoked by alias); 29 Jun 2010 03:13:53 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 15129 Received: (qmail 5358 invoked from network); 29 Jun 2010 03:13:50 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at benizi.com designates 64.130.10.15 as permitted sender) Date: Mon, 28 Jun 2010 23:05:56 -0400 (EDT) From: "Benjamin R. Haskell" To: Joke de Buhr cc: zsh-users@zsh.org Subject: Re: Exit value of command glob qualifier within for loop In-Reply-To: <201006272348.48484.joke@seiken.de> Message-ID: References: <201006272348.48484.joke@seiken.de> User-Agent: Alpine 2.01 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Sun, 27 Jun 2010, Joke de Buhr wrote: > Hi, > > I'm using a for loop with glob qualifiers to process a list of altered > files. It looks like this: > > for a in *(e:age today:); do some_command $a ; done > > > The problem, I've enabled the option PRINT_EXIT_VALUE. Now zsh echoes > the line "zsh: exit 1" for every file which doesn't match the > qualifier. > > If I use this (builtin) command zsh reports the exit status as well: > print *(e:age today:) > > But if I use this (external) command zsh doesn't: > ls *(e:age today:) > > > I'm not sure if this behavior is intentional but it sure is annoying. > Disabling PRINT_EXIT_VALUE before running these commands doesn't make > that much fun. I think zsh shouldn't print the exit value at all. Maybe not the answer you're hoping for, but with very recent zsh[1], the following pair of commands can provide an effect similar to PRINT_EXIT_VALUE while specifically excluding a non-zero return status when inside a glob qualifier: # $1 $2 and $3 are possibly-different versions of the command # $1 seemed fine to me preexec () { _debug_lastcmd=$1 } # Print "(command): exit (status)" to stderr, # unless context contains globqual TRAPZERR () { local ret=$? if (( ! $zsh_eval_context[(Ie)globqual] )) ; then printf "%s: exit %d\n" $_debug_lastcmd $? >&2 fi } NB. I never use PRINT_EXIT_VALUE, nor do I plan to, so I'm not sure what behaviors might be different, behavior-wise. I suspect that PRINT_EXIT_VALUE is finer-grained in its output, for starters. -- Best, Ben [1] Anything past git commit 09960dc (master~39 as of right now), which is where Peter included his zsh_eval_context patch discussed in: zsh-workers 27951: http://www.zsh.org/mla/workers/2010/msg00403.html