How to create a bash variable like $RANDOM

后端 未结 3 1779
不思量自难忘°
不思量自难忘° 2021-01-16 23:46

I\'m interest in some thing : every time I echo $RANDOM , the show value difference . I guess the RANDOM is special (When I read it , it may call a function , s

3条回答
  •  悲&欢浪女
    2021-01-16 23:55

    If you are BASH scripting there is a $RANDOM variable already internal to BASH. This post explains the random variable $RANDOM:

    http://tldp.org/LDP/abs/html/randomvar.html

    It generates a number from 0 - 32767.

    If you want to do different things then something like this:

    case $RANDOM in
    [1-10000])
      Message="All is quiet."
      ;;
    [10001-20000])
      Message="Start thinking about cleaning out some stuff.  There's a partition that is $space % full."
      ;;
    [20001-32627])
      Message="Better hurry with that new disk...  One partition is $space % full."
      ;;
    esac
    

提交回复
热议问题