Bash Continue Command / Script On The Next Line

In a bash script, the continue statement is used to skip the current iteration of a loop and move on to the next iteration. It is commonly used within for or while loops to skip over certain iterations based on certain conditions.

Here’s an example of using continue in a for loop:

for i in {1..10}; do
if [ $((i % 2)) -eq 0 ]; then
continue
fi
echo $i
done

This script will print the odd numbers from 1 to 10, since the continue statement is used to skip over even numbers. The output will be:

1
3
5
7
9

In this example, the if statement checks if the current value of i is even, and if it is, the continue statement is executed and the current iteration is skipped. If the current value of i is odd, the echo command is executed to print the value of i.

So, in short, the continue statement is used in a bash script to skip over certain iterations of a loop and continue with the next iteration.

(Alprazolam)

Leave a Comment