這是我的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
要做的第一件事就是讓它使用一致的縮進。 –