dimanche 14 février 2021

Get last digit of random integer in bash

I'm trying to get a random value for sleep to use in a bash script. The standard

 $x = $[ $RANDOM % 20 + 11 ]

seems to return 12 every time, so instead I am using

RANDOM=$(date +%s%N | cut -b10-19)

But that would be silly for a value for sleep. How do I access an element from the integer returned from the value assigned to RANDOM? e.g. the last digit? I tried

A=$( printf $RANDOM )
echo ${A[3]}

but I get the 'Bad substitution' error (whatever that means). Thanks




Aucun commentaire:

Enregistrer un commentaire