From: Eric Blake <eblake@redhat.com>
To: Fam Zheng <famz@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, kwolf@redhat.com, mjt@tls.msk.ru,
stefanha@redhat.com, mreitz@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2] tests: Use "command -v" instead of which(1) in shell scripts
Date: Wed, 19 Nov 2014 06:19:29 -0700 [thread overview]
Message-ID: <546C98E1.3070905@redhat.com> (raw)
In-Reply-To: <1416380832-9697-1-git-send-email-famz@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1578 bytes --]
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.
>
> Fix it by using "command -v", a native way to query the existence of a
> command.
>
> Suggested-by: Eric Blake <eblake@redhat.com>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> +++ b/tests/qemu-iotests/common.config
> @@ -47,7 +47,7 @@ export PWD=`pwd`
> # $1 = prog to look for, $2* = default pathnames if not found in $PATH
> set_prog_path()
> {
> - p=`which $1 2> /dev/null`
> + p=`command -v $1 2> /dev/null`
Reviewed-by: Eric Blake <eblake@redhat.com>
> 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.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 539 bytes --]
next prev parent reply other threads:[~2014-11-19 13:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-19 7:07 [Qemu-devel] [PATCH v2] tests: Use "command -v" instead of which(1) in shell scripts Fam Zheng
2014-11-19 13:19 ` Eric Blake [this message]
2014-11-19 14:07 ` Peter Maydell
2014-11-26 16:21 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=546C98E1.3070905@redhat.com \
--to=eblake@redhat.com \
--cc=famz@redhat.com \
--cc=kwolf@redhat.com \
--cc=mjt@tls.msk.ru \
--cc=mreitz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).