Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图在 Bash 中生成一个随机数,但看起来 $RANDOM 总是返回零。
我正在使用以下代码
#!/bin/sh #!/bin/bash testing=$((RANDOM)) echo $testing VAR=$((RANDOM%200+100)) echo $VAR
结果 :
0 100
有人知道如何解决这个问题吗?
#!/bin/sh从脚本中删除该行。$RANDOM在 中工作bash,不在sh。
#!/bin/sh
$RANDOM
bash
sh