Generate a random number 🔢 in Unix Shell Script

Generate a random number 🔢 in Unix Shell Script

Here is how to generate a random number in a bash shell script. In the bash shell we have environmental variable $RANDOM that can generate a unique random number each time it is referenced.

echo $RANDOM

And to assign this value to a variable :

var=$RANDOM
image 1 - Generate a random number 🔢 in Unix Shell Script
whoami
Stefan Pejcic
Join the discussion

I enjoy constructive responses and professional comments to my posts, and invite anyone to comment or link to my site.