在bash中,支持$RANDOM系统变量,范围是 [0, 32767]
$RANDOM
#!/bin/bash set -e randN() { local N=$1 echo $(($RANDOM%$N)) } while [ true ]; do echo `randN 100` sleep 1s done
我在树莓派上用sh命令运行脚本发现$RANDOM为空,但是用bash可以正常运行。
sh
bash