From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 45E871581FB for ; Sun, 24 Nov 2024 14:12:51 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4D1DEE0819; Sun, 24 Nov 2024 14:12:46 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id C26A5E0801 for ; Sun, 24 Nov 2024 14:12:45 +0000 (UTC) From: =?utf-8?Q?Ulrich_M=C3=BCller?= To: =?utf-8?B?TWljaGHFgiBHw7Nybnk=?= Cc: gentoo-dev@lists.gentoo.org Subject: Re: [gentoo-dev] New eclass: eapi9-pipestatus.eclass In-Reply-To: <5e0e2dd372bf3a60a9c2dfb8b68bf7b18b7c2b99.camel@gentoo.org> (=?utf-8?Q?=22Micha=C5=82_G=C3=B3rny=22's?= message of "Sun, 24 Nov 2024 13:58:04 +0100") References: <5e0e2dd372bf3a60a9c2dfb8b68bf7b18b7c2b99.camel@gentoo.org> Date: Sun, 24 Nov 2024 15:12:36 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Archives-Salt: a6951925-de58-493b-a169-271273fbccf7 X-Archives-Hash: 294d9f85db0ad936d8c5770d865f2047 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >>>>> On Sun, 24 Nov 2024, Micha=C5=82 G=C3=B3rny wrote: >> # @CODE >> # local status >> # foo | bar >> # status=3D$(pipestatus -v) || die "foo | bar failed, status ${status}" > I suppose you may want to put a verbose warning not to put "local" > on the same line, because people are going to do that as an "obvious" > optimization. Thank you for the feedback. I have added the following: # Caveat: "pipestatus" must be the next command following the pipeline. # In particular, the "local" declaration must be before the pipeline, # otherwise it will reset the status. >> [[ $# -gt 0 && ${1} !=3D -v || $# -gt 1 ]] \ > Please use parentheses when you combine && and ||, if only for the sake > of readability. I've replaced it by: [[ $# -gt 0 && ( ${1} !=3D -v || $# -gt 1 ) ]] Note that [[ ( $# -gt 0 && ${1} !=3D -v ) || $# -gt 1 ]] would also work, i.e. order doesn't matter (the reason is that "-gt 1" implies "-gt 0"). >> && die "${FUNCNAME}: bad arguments: $@" > Replace the '\' with the '&&'. We don't have any policy on this, and IMHO it is clearer to split the line before the operator. (This is also what the GNU coding standards say, and what is used in mathematical typesetting.) >> [[ ${1} =3D=3D -v ]] && echo "${status[@]}" >>=20 >> for s in "${status[@]}"; do >> [[ ${s} -ne 0 ]] && ret=3D${s} > I suppose it's just my C-foo talking and completely needless > optimization here, but it really itches me to iterate the array > backwards and return on the first match. I had considered this and decided against it, see the last paragraph of https://bugs.gentoo.org/566342#c13: | Alternatively, one could loop backwards over the array (and return | for the first nonzero status) but it would be more complicated. | I don't think that would be more efficient because the normal case | is that all stat=C5=ABs are zero. Plus, pipelines rarely consist of more | than 3 commands. Ulrich --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQFDBAEBCAAtFiEEtDnZ1O9xIP68rzDbUYgzUIhBXi4FAmdDNFQPHHVsbUBnZW50 b28ub3JnAAoJEFGIM1CIQV4uhdkH/RGw66breGhWK9zfHitwudal4WobrWEIGMKR X2KxjWjUlHi4qG2spoSUwAasVx2ebwFbdjJVBrarNWyOBGn+DLyH3GI3xNgT9sa/ 65kuQdvLmYA9fIM4FXC3AzAV2py3xWg7cHIHwBMEF3anpkvseQL+0FjuxfBKXhEX qFrqz/pnTSc/a4lL8jCkGbeJSmQIHMuzlZMO54N7Eu4Rpb9rRNd61R4YUdbsExUm Wcwd6H22BsmcidxdiFdIyB9aCg9wN2l2WDWXvOadmW7ZovE9kisZP9vWPBnjejyh CKdSjs4BlmfDnjBnPLsdqqiZC3Gj2sR0COTPrhZcK9IpqKn4YK4= =FbjP -----END PGP SIGNATURE----- --=-=-=--