In a Bash Script how does the continue command work with embedded loops?

11,266

From "help continue":

continue: continue [n]
    Resume for, while, or until loops.

    Resumes the next iteration of the enclosing FOR, WHILE or UNTIL loop.
    If N is specified, resumes the Nth enclosing loop.

    Exit Status:
    The exit status is 0 unless N is not greater than or equal to 1.

So you want continue or continue 1 to go to the next iteration of until, or continue 2 to go to the next iteration of while.

Share:
11,266

Related videos on Youtube

Artyom Zankevich
Author by

Artyom Zankevich

Updated on September 18, 2022

Comments

  • Artyom Zankevich
    Artyom Zankevich almost 2 years

    I am writing a bash script in a busybox session.

    The script has to initiate an external executable numerous times in sequence in daemonised form then monitor the output.

    while read LINE; do
      VARIABLEPARAMETER=`echo "$LINE" | sed -e 's/appropriateregex(s)//'`
      externalprog --daemonize -acton $VARIABLEPARAMETER -o /tmp/outputfile.txt
      until [ "TRIGGERED" = "1" ]; do
        WATCHOUTPUT=`tail -n30 /tmp/outputfile.txt`
        TRIGGERED=`echo "$WATCHOUTPUT" | grep "keyword(s)"` 
        if [ -z "$TRIGGERED" ]; then
          PROGID=`pgrep externalprog`
          kill -2 "$PROGID"
          continue
        fi
      done
    done < /tmp/sourcedata.txt
    

    My question is which of the two loops will the continue command be executed against?

    The initial while read line, or the subsequent, until triggered?

    Please don't get to focused on the actual code I've thrown this together as an example to try to explain this question, the actual code is much more detailed.