这是我的bash脚本代码,所以我想知道如何使用“for”循环而不是“while”循环来重写下面的Bash脚本。如何将'bash'while循环重写为'for'循环?
#!/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循环](http://stackoverflow.com/questions/49110/how-do-i-write-a-for- loop-in-bash) – BroSlow
要做的第一件事就是让它使用一致的缩进。 –