bash linux while loop command code example
Example 1: shell script:while done
while [ condition ]
do
command1
command2
command3
done
while [ condition ]; do commands; done
while control-command; do COMMANDS; done
x=1
while [ $x -le 5 ]
do
echo "Welcome $x times"
x=$(( $x + 1 ))
done
x=1; while [ $x -le 5 ]; do echo "Welcome $x times" $(( x++ )); done
counter=$1
factorial=1
while [ $counter -gt 0 ]
do
factorial=$(( $factorial * $counter ))
counter=$(( $counter - 1 ))
done
echo $factorial
$ chmod +x script.sh
$ ./script.sh 5
Example 2: linux while loop
while true;
do
;done