bash can express a similar idea. Let’s say we wanted to display five numbers in sequential order from 1 to 5. A
bash script could be constructed as follows:
#!/bin/bash # while-count: display a series of numbers count=1 while [ $count -le 5 ]; do echo $count count=$((count + 1)) done echo "Finished."
When executed, this script displays the following:
while-count1 2 3 4 5 Finished.
The syntax of the
while command is:
while commands; do commands; done
while evaluates the exit status of a list of commands. As long as the exit status is 0, it performs the commands inside the loop. In the script above, the variable
count is created and assigned an initial value of 1. The
while command evaluates the exit status of the