Emulating a do-while loop in Bash

What is the best way to emulate a do-while loop in Bash?

I could check for the condition before entering the while loop, and then continue re-checking the condition in the loop, but that’s duplicated code. Is there a cleaner way?

Pseudo code of my script:

while [ current_time <= $cutoff ]; do
    check_if_file_present
    #do other stuff
done

This doesn’t perform check_if_file_present if launched after the $cutoff time, and a do-while would.

4 Answers
4

Leave a Comment