Learning Bash Scripts (3)

This post covers the loop usage of bash shell. NOTE: read inline comments carefully 🙂

1. for loop

2. while loop

3. until loop

4. break & continue

There may be times when you’re in an inner loop but need to stop the outer loop. The break command includes a single command line parameter value: break n where n indicates the level of the loop to break out of. By default, n is 1, indicating to break out of the current loop. If you set n to a value of 2, the break command will stop the next level of the outer loop.

5. redirect & pipe

Finally, you can either pipe or redirect the output of a loop within your shell script.

Leave a Reply

Your email address will not be published. Required fields are marked *