From: Eric Blake <eblake@redhat.com>
To: Kamil Rytarowski <n54@gmx.com>,
Peter Maydell <peter.maydell@linaro.org>,
qemu-devel@nongnu.org
Cc: patches@linaro.org
Subject: Re: [Qemu-devel] [PATCH] tests: Handle $RANDOM not being supported by the shell
Date: Fri, 14 Jul 2017 07:02:10 -0500 [thread overview]
Message-ID: <64d381ca-ce9a-a19b-0e6f-8ad287d27361@redhat.com> (raw)
In-Reply-To: <910a8148-915a-ab66-1c6c-f18145c13e37@gmx.com>
[-- Attachment #1: Type: text/plain, Size: 1209 bytes --]
On 07/14/2017 06:27 AM, Kamil Rytarowski wrote:
> On 14.07.2017 12:45, Peter Maydell wrote:
>> In various places in our test makefiles and scripts we use the
>> shell $RANDOM to create a random number. This is a bash
>> specific extension, and doesn't work on other shells.
>
> This is supported on other shells like ksh (Korn Shell), but still as an
> extension.
>
>> With dash the shell doesn't complain, it just effectively
>> always evaluates $RANDOM to 0:
>> echo $((RANDOM + 32768)) => 32768
>>
>> However, on NetBSD the shell will complain:
>> "-sh: arith: syntax error: "RANDOM + 32768"
>>
>
> I will make sure whether this behavior is correct in our sh(1).
The question is what your shell does for:
unset foo
echo $(( foo % 255 ))
if it reliably prints 0, then it would do the same when RANDOM is an
undefined (and not a magic) variable. Presumably, where sh is going
wrong is that it is treating an undefined variable not as 0, but as a
syntax error, and you'd get that behavior regardless of whether RANDOM
is in the mix.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2017-07-14 12:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-14 10:45 [Qemu-devel] [PATCH] tests: Handle $RANDOM not being supported by the shell Peter Maydell
2017-07-14 11:27 ` Kamil Rytarowski
2017-07-14 11:50 ` Kamil Rytarowski
2017-07-14 12:02 ` Eric Blake [this message]
2017-07-14 11:41 ` Fam Zheng
2017-07-14 12:03 ` Eric Blake
2017-07-17 9:43 ` Stefan Hajnoczi
2017-07-20 11:26 ` Markus Armbruster
2017-07-20 15:34 ` Peter Maydell
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=64d381ca-ce9a-a19b-0e6f-8ad287d27361@redhat.com \
--to=eblake@redhat.com \
--cc=n54@gmx.com \
--cc=patches@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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).