sh shell脚本无法打破循环

时间:2023-01-27 23:08:10

sh script should work while file size = 0(i checked manually with stat if it doesn't download file the value is "0") but it didn't stop so i added "if" statement with break, still doesn't work, how can i break it? Please help.

sh脚本应该工作,而文件大小= 0(我用stat手动检查,如果它不下载文件的值是“0”)但它没有停止所以我添加“如果”语句与休息,仍然不起作用,我该怎么打破它?请帮忙。

Note: there might be other ways to download firefox automaticly but i put here firefox just as a lightweight example.

注意:可能还有其他方法可以自动下载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

Ok, i figured it out:

好吧,我想通了:

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

1 个解决方案

#1


1  

You are just breaking the inner most for loop, if you are trying to exit the script at that point, maybe you should use exit?

你只是打破了内部循环,如果你想在那时退出脚本,也许你应该使用exit?

#1


1  

You are just breaking the inner most for loop, if you are trying to exit the script at that point, maybe you should use exit?

你只是打破了内部循环,如果你想在那时退出脚本,也许你应该使用exit?