From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr5Ak-0003Vv-CD for qemu-devel@nongnu.org; Wed, 19 Nov 2014 08:19:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xr5Af-0006wC-Dy for qemu-devel@nongnu.org; Wed, 19 Nov 2014 08:19:50 -0500 Message-ID: <546C98E1.3070905@redhat.com> Date: Wed, 19 Nov 2014 06:19:29 -0700 From: Eric Blake MIME-Version: 1.0 References: <1416380832-9697-1-git-send-email-famz@redhat.com> In-Reply-To: <1416380832-9697-1-git-send-email-famz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="mPqOOViVl5uIoJ3x95o78vbxllxs0HWNR" Subject: Re: [Qemu-devel] [PATCH v2] tests: Use "command -v" instead of which(1) in shell scripts List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, kwolf@redhat.com, mjt@tls.msk.ru, stefanha@redhat.com, mreitz@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --mPqOOViVl5uIoJ3x95o78vbxllxs0HWNR Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 11/19/2014 12:07 AM, Fam Zheng wrote: > When which(1) is not installed, we would complain "perl not found" > because it's the first set_prog_path check. The error message is > wrong. >=20 > Fix it by using "command -v", a native way to query the existence of a > command. >=20 > Suggested-by: Eric Blake > Signed-off-by: Fam Zheng > +++ b/tests/qemu-iotests/common.config > @@ -47,7 +47,7 @@ export PWD=3D`pwd` > # $1 =3D prog to look for, $2* =3D default pathnames if not found in $= PATH > set_prog_path() > { > - p=3D`which $1 2> /dev/null` > + p=3D`command -v $1 2> /dev/null` Reviewed-by: Eric Blake > if [ -n "$p" -a -x "$p" ]; then Unrelated: this line "works" because this is a /bin/bash script, but it is non-portable. Use of -a and -o inside [] is a mistake waiting to happen. For example, is [ ! "$a" -a "$b" ] supposed to be true or false for all values of $a and $b? Naively, this says return true if '! "$a"' (a is empty) and '"$b"' (b is non-empty); but if $a is '(' and $b is ')' it could also be parsed as returning the negation of whether the parenthesized string "-a" is non-empty. Use of -a and -o in [[]] is a bit better, but I still HIGHLY recommend that constructs like this be rewritten as [ -n "$p" ] && [ -x "$p" ] for avoidance of confusion and prevention of copy-pasting the test to non-bash shells. But that would be a separate patch. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --mPqOOViVl5uIoJ3x95o78vbxllxs0HWNR Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg iQEcBAEBCAAGBQJUbJjhAAoJEKeha0olJ0Nqt2wIAIW1r/VOJB5hJEW6sviTWjhe a/rahj0Y5GS4od8NLfD6UM9R4Kul9c+7PGCM4IPRYsl+DOnD86jUziFKrhcsgCN0 F4ksLO3NCztWOyRDw96kzbMVK+Sk3XFTd0GyBhIr8cZbVMCL1Tz8u4mRqKc3JR/L XnMMz49RukZOu3xqwHnm5RcjVFDTjWBe3t7rrl3JLeoT+wz40iVbAaVc4VlVeJlx 6LiOvpmYf6gjBNIy6ZLzCgWwvq65ELcOBIC5gBHZxF2fFcsE+DxJoM/SFPy00Ilu ji97N/VLc/gVbfK3WSHYmB7IVUQ+HQpmo/Jsav283Woa8Cg6MeZ7v76yJgEyDEI= =3HbN -----END PGP SIGNATURE----- --mPqOOViVl5uIoJ3x95o78vbxllxs0HWNR--