Does KornShell (ksh) have a Do...While loop? Does KornShell (ksh) have a Do...While loop? unix unix

Does KornShell (ksh) have a Do...While loop?


Yes, the standard while loop in ksh supports this out of the box:

while ...; do ...; done

The standard while loop has code blocks before and after do.

Each block may contain multiple commands. Conventionally we use onlya single command for the first block, and its exit status determines whetherthe loop terminates or is continued.

When we use multiple commands, onlythe status of the last command matters.

while   echo do this always # replace with your code   [[ -n "${FILES%%,*}" ]]do   FILE="${FILES%%,*}"                                FILES="${FILES#*,}"done


you could fake it:

do_once=truewhile $do_once || [[ other condition ]]; do  : your stuff here  do_once=falsedone


There is no such construct in ksh. You can emulate this by break (or continue) at the end of a while true; do ... ; done loop.