0
  while true; do
    <do this>
    for a in 1 2 3 4 5; do
       <<do this>>
    done
        if [ "$someVar1" == "$someVar2" ]; then

            if [ -f "$numberOfFiles" ]; then
                if [ "$countValue1" == "$countValue2" ]; then
                    <<do this>>
                    break     
            else
        echo "in the else part"
       done
      done

While trying the above code I want to get completely out of the third if statement and for that I m using break. But the break statement is getting out of the if and going into the else part and iterating over and over again. How do I get out of the while loop?

0

1 Answer 1

4

From help break:

break: break [n] Exit for, while, or until loops.

Exit a FOR, WHILE or UNTIL loop.  If N is specified, break N enclosing
loops.

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

break supports an optional argument: the number of enclosing loops to break.

In your example it would be

break 3
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.