How do i produce a random number in a bash shell script?



  • Man page for bash.

    One way is to use the RANDOM variable. This could be useful if you want to produce output to temporary files and needs a random number to make the files names different.

    $ echo $RANDOM
    1048
    $ echo $RANDOM
    22174
    $ echo $RANDOM
    19572
    $ echo $RANDOM
    26971
    
    $ touch /tmp/command.out.$RANDOM
    $ ls -ld /tmp/command.out*
    -rw-r--r-- 1 parallels parallels 0 Apr  8 18:44 /tmp/command.out.25266
    

Log in to reply
 

© Lightnetics 2024