Do while loop

As an alternative, we have included the do while loop. It is similar to a for loop, but better suited to dynamic conditions, such as when you do not know when a value will be returned or performing a task until a condition is met. The condition within the square brackets is the same as an if statement:

#!/bin/bashCTR=1while [ ${CTR} -lt 9 ]do    echo "CTR var: ${CTR}"    ((CTR++)) # Increment the CTR variable by 1doneecho "Finished"

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.