bashshellrandom

Generating random number between 1 and 10 in Bash Shell Script


How would I generate an inclusive random number between 1 to 10 in Bash Shell Script?

Would it be $(RANDOM 1+10)?


Solution

  • $(( ( RANDOM % 10 )  + 1 ))
    

    EDIT. Changed brackets into parenthesis according to the comment. http://web.archive.org/web/20150206070451/http://islandlinux.org/howto/generate-random-numbers-bash-scripting