run one command in while loop bash code example
Example 1: while bash one line
while CONDITION_STATEMENT; do SOME_CODE; done
Example 2: 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