* Re: Exit value of command glob qualifier within for loop
@ 2010-06-29 7:56 Joke de Buhr
0 siblings, 0 replies; 3+ messages in thread
From: Joke de Buhr @ 2010-06-29 7:56 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 2343 bytes --]
On Tuesday 29 June 2010 05:05:56 Benjamin R. Haskell wrote:
> 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.
You're right it isn't (shouldn't) be quite that powerful as PRINT_EXIT_VALUE.
PRINT_EXIT_VALUE has the benefit of printing the exit values of commands within
piped expressions in case something went wrong.
$ print "asdf" | cat | false | cat
zsh: done print "asdf" | cat |
zsh: exit 1 false |
zsh: done cat
The suggested code seems to be more like a "only the last" exit value just
like the last exit value echoed within prompts. It's a good think I'm not
using glob qualifiers with commands that often so it's not too complicated to
ignore the "zsh: exit 1" lines.
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 706 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Exit value of command glob qualifier within for loop
@ 2010-06-27 21:48 Joke de Buhr
2010-06-29 3:05 ` Benjamin R. Haskell
0 siblings, 1 reply; 3+ messages in thread
From: Joke de Buhr @ 2010-06-27 21:48 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: Text/Plain, Size: 709 bytes --]
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.
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 706 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Exit value of command glob qualifier within for loop
2010-06-27 21:48 Joke de Buhr
@ 2010-06-29 3:05 ` Benjamin R. Haskell
0 siblings, 0 replies; 3+ messages in thread
From: Benjamin R. Haskell @ 2010-06-29 3:05 UTC (permalink / raw)
To: Joke de Buhr; +Cc: zsh-users
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-06-29 7:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-29 7:56 Exit value of command glob qualifier within for loop Joke de Buhr
-- strict thread matches above, loose matches on Subject: below --
2010-06-27 21:48 Joke de Buhr
2010-06-29 3:05 ` Benjamin R. Haskell
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).