From: Eric Blake <eblake@redhat.com>
To: Jeff Cody <jcody@redhat.com>, Fam Zheng <famz@redhat.com>
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com,
benoit@irqsave.net
Subject: Re: [Qemu-devel] [PATCH v2 4/5] block: qemu-iotests - fix image cleanup when using spaced pathnames
Date: Thu, 10 Apr 2014 08:43:44 -0600 [thread overview]
Message-ID: <5346AE20.4040903@redhat.com> (raw)
In-Reply-To: <20140410125356.GD4859@localhost.localdomain>
[-- Attachment #1: Type: text/plain, Size: 2438 bytes --]
On 04/10/2014 06:53 AM, Jeff Cody wrote:
>>> +++ b/tests/qemu-iotests/common.rc
>>> @@ -178,10 +178,10 @@ _rm_test_img()
>>> local img=$1
>>
>> Since we are quoting $img, should we quote $1 as well?
>>
>
> I believe not, because variable assignment won't undergo all the shell
> expansions. Notably, in variable assignment word splitting is not
> performed on the parameter expansion on the argument immediately to the
> right of the '='. Quote removal, however, will still be performed. So
> img=$1 and img="$1" are identical once processed.
Ooh, tricky.
You are correct that in isolation:
img=$1
img="$1"
are semantically identical, no matter what $1 contains, across ALL
shells. However, that's not the code you wrote above.
local img=$1
is not POSIX (yet - although there has been some effort in the POSIX
working group to standardize some form of local variables while still
allowing for the fact that bash and ksh implemented scoping of local
variables differently). But 'local' is similar to 'export'; and observe
the difference when using 'export' between dash and bash:
$ dash -c 'set "a b"; export a=$1 b="$1"; echo "$a.$b"'
a.a b
$ bash -c 'set "a b"; export a=$1 b="$1"; echo "$a.$b"'
a b.a b
Here, the shell word a=$1 is semantically NOT a raw assignment, but
rather an argument to 'export', and arguments DO undergo word splitting
in the current wording of POSIX. There was a recent bug report stating
that the dash behavior (which is strictly POSIX) is undesirable, and
that the bash/ksh behavior of export, while not strictly compliant with
the POSIX 2008 wording, is nicer; so the next version of POSIX will be
amended to add a definition of a 'declaration utility' which can
evaluate (some) arguments in assignment context. 'export' is one such
declaration utility, 'local' (if it gets standardized) would be another:
http://austingroupbugs.net/view.php?id=351
But even with the notion of an assignment-context argument added to a
future version of POSIX, the reality is that given the present standard,
it's safer to either use "" to ensure no word splitting:
local img="$1"
or to rewrite things across two statements to avoid relying on whether
assignment-context arguments work the way you want:
local img
img=$1
--
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: 604 bytes --]
next prev parent reply other threads:[~2014-04-10 14:43 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-10 2:41 [Qemu-devel] [PATCH v2 0/5] Add common QEMU control functionality to qemu-iotests Jeff Cody
2014-04-10 2:41 ` [Qemu-devel] [PATCH v2 1/5] block: qemu-iotests - add common.qemu, for bash-controlled qemu tests Jeff Cody
2014-04-10 5:27 ` Fam Zheng
2014-04-10 19:07 ` Jeff Cody
2014-04-10 2:41 ` [Qemu-devel] [PATCH v2 2/5] block: qemu-iotests - update 085 to use common.qemu Jeff Cody
2014-04-10 6:10 ` Fam Zheng
2014-04-10 19:28 ` Jeff Cody
2014-04-10 2:41 ` [Qemu-devel] [PATCH v2 3/5] block: qemu-iotests - test for live migration Jeff Cody
2014-04-10 6:16 ` Fam Zheng
2014-04-10 11:10 ` Jeff Cody
2014-04-10 2:41 ` [Qemu-devel] [PATCH v2 4/5] block: qemu-iotests - fix image cleanup when using spaced pathnames Jeff Cody
2014-04-10 7:53 ` Fam Zheng
2014-04-10 12:53 ` Jeff Cody
2014-04-10 14:43 ` Eric Blake [this message]
2014-04-10 14:48 ` Eric Blake
2014-04-10 18:09 ` Jeff Cody
2014-04-11 0:59 ` Fam Zheng
2014-04-10 2:41 ` [Qemu-devel] [PATCH v2 5/5] block: qemu-iotests: make test 019 and 086 work with " Jeff Cody
2014-04-10 7:51 ` Fam Zheng
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=5346AE20.4040903@redhat.com \
--to=eblake@redhat.com \
--cc=benoit@irqsave.net \
--cc=famz@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@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).