qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] tests: Handle $RANDOM not being supported by th


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH] tests: Handle $RANDOM not being supported by the shell
Date: Fri, 14 Jul 2017 07:02:10 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

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: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]