7

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.

13

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.