From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5124 invoked by alias); 29 Jun 2010 07:56:45 -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: 15130 Received: (qmail 20211 invoked from network); 29 Jun 2010 07:56:42 -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 seiken.de designates 94.23.38.107 as permitted sender) To: zsh-users@zsh.org Subject: Re: Exit value of command glob qualifier within for loop From: Joke de Buhr Date: Tue, 29 Jun 2010 09:56:29 +0200 MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart2527505.25v7S4xAN6"; protocol="application/pgp-signature"; micalg=pgp-ripemd160 Content-Transfer-Encoding: 7bit Message-Id: <201006290956.31636.joke@seiken.de> --nextPart2527505.25v7S4xAN6 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Tuesday 29 June 2010 05:05:56 Benjamin R. Haskell wrote: > On Sun, 27 Jun 2010, Joke de Buhr wrote: > > Hi, > >=20 > > I'm using a for loop with glob qualifiers to process a list of altered > >=20 > > files. It looks like this: > > for a in *(e:age today:); do some_command $a ; done > >=20 > > 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. > >=20 > > If I use this (builtin) command zsh reports the exit status as well: > > print *(e:age today:) > >=20 > > But if I use this (external) command zsh doesn't: > > ls *(e:age today:) > >=20 > > 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. >=20 > 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: >=20 > # $1 $2 and $3 are possibly-different versions of the command > # $1 seemed fine to me > preexec () { _debug_lastcmd=3D$1 } >=20 > # Print "(command): exit (status)" to stderr, > # unless context contains globqual > TRAPZERR () { > local ret=3D$? > if (( ! $zsh_eval_context[(Ie)globqual] )) ; then > printf "%s: exit %d\n" $_debug_lastcmd $? >&2 > fi > } >=20 > 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_VALU= E. PRINT_EXIT_VALUE has the benefit of printing the exit values of commands wi= thin=20 piped expressions in case something went wrong. $ print "asdf" | cat | false | cat =20 zsh: done print "asdf" | cat |=20 zsh: exit 1 false |=20 zsh: done cat The suggested code seems to be more like a "only the last" exit value just= =20 like the last exit value echoed within prompts. It's a good think I'm not=20 using glob qualifiers with commands that often so it's not too complicated = to=20 ignore the "zsh: exit 1" lines. --nextPart2527505.25v7S4xAN6 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iQG7BAABAwAlBQJMKactHhhoa3A6Ly9wb29sLnNrcy1rZXlzZXJ2ZXJzLm5ldAAK CRCWUloJhwFWxqIQC/wJ8BE5FRn9ymscEGPI2pY3Rw9L8NAik7dgKHxtSPuLrDgX E3GB0KFunj3pdErIffJdqkMkgkKO8ULizcu1jie+aZG87KiAxFy+0B5RvzhhSkEp wi759XmaTtCV2RpEdrLqlm+5Z4vl++Ur8bg1mRP8hx38SieKQbXCtssH58R/WEAK Ax7uyiWjgWWbUUPUrOe/1Ogr6Zv1xyU6r0x5DjbaerNfdAgZyeXthX2VHc0LgpIt NqgCmrM6aPUOE8gs9824ACddffV91haAyOhIZt0P7egbWM6JEhvSONGEhtENiVF3 Pg9N7zxKKWppR4BgE/9TX7HtAc+pUmNOy4/TJqNAWHiCz3nMzOnfHLHesWXblZNd 5XINdcNO/1hNhazy3cWe8iJLzVCbFWvN6+18KwuMHtIWezVSAI4+2QimQ35a77JI UnsE/ASKnYAT/VFH30kM1h7ZB7yYkiw58Ia5yQEGzi81OmP9XfV7gPCo2MhX3BK5 u/lazKNZyNmbwBHyNs0= =nDn4 -----END PGP SIGNATURE----- --nextPart2527505.25v7S4xAN6--