2013-08-22 121 views
0

sh脚本应该工作而文件大小= 0(我用手动检查统计,如果不下载文件中的值为“0”),但它并没有停止,所以我加入“if”声明中断,仍然不起作用,我怎么能打破它?请帮忙。SH shell脚本不能打破循环

注:可能有其他的方式来下载Firefox全自动但是我把这里的Firefox只是作为一个轻量级的例子。

n=0 
mm=22 

while [ $n -eq 0 ]; do 
    for a in $mm 
    do 
    for b in 0 1 2 3 4 5 6 7 8 9 
    do 
     for c in "" ".1" ".2" 
     do 
     wget -O ff.exe http://download.cdn.mozilla.net/pub/firefox/releases/latest/win32/ru/Firefox%20Setup%20$a.$b$c.exe 
     n=$(stat -c %s ff.exe) 
     echo "n = $n" 
     if [ $n -ne 0 ]; then 
      echo "n2 = $n" 
      break 
     fi 
     done 
    done 
    mm=$(($mm + 1)) 
    done 
done 

好吧,我想通了:

n=0 
mm=22 

while [ $n -eq 0 ]; do 
    for a in $mm 
    do 
    for b in 1 2 0 3 4 5 6 7 8 9 
    do 
     if [ $n -ne 0 ]; then 
    break 
     fi 
     for c in "" ".1" ".2" 
     do 
    wget -O ff.exe http://download.cdn.mozilla.net/pub/firefox/releases/latest/win32/ru/Firefox%20Setup%20$a.0$c.exe 
    n=$(stat -c %s ff.exe) 
     if [ $n -ne 0 ]; then 
     break 
     fi 
     done 
    done 
    mm=$(($mm + 1)) 
    done 
done 
+0

问题是什么?你是说“break”会导致脚本退出吗? – devnull

回答

1

你只是打破了内心最for循环,如果你想在这一点上退出脚本,也许你应该使用exit