On 07/13/2017 01:40 PM, Kamil Rytarowski wrote:
>> MALLOC_PERTURB_=${MALLOC_PERTURB_:-$((RANDOM % 255 + 1))} gtester -k
>> --verbose -m=quick tests/check-qdict
>> sh: arith: syntax error: "RANDOM % 255 + 1"
>>
>> likely because we're using a bashism there.
Yes, assuming that $RANDOM exists is a bashism.
>>
>
> This is an extension to a POSIX shell. We were lately adding it as an
> extension to our sh(1) in the distribution. Were also thinking about
> prompting POSIX to standarize it.
>
> $ echo $((RANDOM % 255))
> 52
>
> As of now, one portable solution is to parse /dev/urandom, or use a 3rd
> party tool like awk(1).
It's also portable (although less random) to do:
$(( ${RANDOM:-0} + 1))
(the whole idea of MALLOC_PERTURB_ only works on glibc anyways, so it
really doesn't matter what you set it to on other systems).
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
