How to use loops in bash or shell script with examples.
Here we will see the way of using Loops in bash or shell script
As we all knows In computer programming, a loop is a sequence of instructions that is continually repeated until a certain condition is reached.
For loop syntax
for (( initializer; condition; step )) do statement done
While loop syntax
while [ condition ] do statement done
Until Loop syntax
until [ condition ] do statement done
Execution
$ ./loop.sh
Output
1 2 3 4 5 6 7 8 9 10 For Loop 1 2 3 4 5 6 7 8 9 10 Sum of all digits Enter a number: 443 Sum=11 Largest of n nubmers How many numbers: 5 Enter Numbers 23 4 5123 432 4 Max number is 5123 0 1 2 3 4 5 6 7 8 9 10
Hope this may help you.
Comments
Leave a comment
You are not LoggedIn but you can comment as an anonymous user which requires manual approval. For better experience please Login.