How to break out of a loop in Bash?

I want to write a Bash script to process text, which might require a while loop.

For example, a while loop in C:

int done = 0;
while(1) {
  ...
  if(done) break;
}

I want to write a Bash script equivalent to that. But what I usually used and as all the classic examples I read have showed, is this:

while read something;
do
...
done

It offers no help about how to do while(1){} and break;, which is well defined and widely used in C, and I do not have to read data for stdin.

Could anyone help me with a Bash equivalent of the above C code?

2 Answers
2

Leave a Comment