until
command is opposite of while
command. It executes a set of commands when condition evaluates to non-zero and when the condition returns zero exit status then it does not execute the commands listed between do
and done
.
until [ condition ] do commands done
read -p "Enter a number: " number i=1 until [ $i -eq 11 ] do echo "$number x $i = $((number*i))" i=$((i+1)) done
Output of the above program
Enter a number: 9 9 x 1 = 9 9 x 2 = 18 9 x 3 = 27 9 x 4 = 36 9 x 5 = 45 9 x 6 = 54 9 x 7 = 63 9 x 8 = 72 9 x 9 = 81 9 x 10 = 90