Bash (Scripting) - Move onto next value in a loop (continue)

by
Jeremy Canfield |
Updated: November 20 2020
| Bash (Scripting) articles
The continue operator is used to move onto the next value in a loop. For example, consider the following script. This script will print the text one two three four to the console.
#!/bin/bash
values="one two three four"
for value in $value {
echo $value
}
In this example, if two is detected, the loop will move onto the next value. In this example, text one three four will be printed to the console.
#!/bin/bash
values="one two three four"
for value in $value {
if [ "$value" == "two" ]; then
continue
fi
echo $value
}
Did you find this article helpful?
If so, consider buying me a coffee over at