简体   繁体   中英

sh shell script can't break the loop

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.

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

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

您只是打破了最内层的for循环,如果您此时试图退出脚本,也许应该使用exit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM