【发布时间】:2014-09-03 04:24:27
【问题描述】:
这是我的 bash 脚本代码,所以我想知道如何使用“for”循环而不是“while”循环来重写下面的 Bash 脚本。
#!/bin/bash
if [ $# -gt 0 ]; then
a=0;
if [ -f RandNos ]; then
rm RandNos;
fi
while [ $a -lt $1 ]
do
a='expr $a + 1';
myrand=$RANDOM;
if [ "$2" "1"]; then
echo "No. $a ==> $myrand";
fi
echo $myrand>>RandNos
done
else
echo "please use with an argument..."
fi
谢谢。
【问题讨论】:
-
为什么?语法重写没有意义......
-
首先要做的是让它使用一致的缩进。
-
感谢您的帮助
标签: bash for-loop while-loop