I am trying to write a script to get a random, even hex number. I have found the the openssl
command has a convenient option for creating random hex numbers. Unfortunately, I need it to be even and my script has a type casting error somewhere. Bash thinks that my newly generated hex number is a string, so when I try to mod it by 2, the script fails. Here is what I have so far:
...
hexVal="$(openssl rand -hex 1)"
while [ `expr $hexVal % 2` -ne 0 ]
do
hexVal="$(openssl rand -hex 1)"
done
...
I have tried various other combinations as well, to no avail. If someone could tell me what is wrong with my syntax, it would be greatly appreciated.