Bash script for loop

This type of for bash script for loop is characterized by counting. The range is specified by a beginning (#1) and ending number (#5). The for loop executes a sequence of commands for each member in a list of items. A representative example in BASH is as follows to display welcome message 5 times with for loop:

#!/bin/bash
for i in 1 2 3 4 5
do
   echo "Welcome $i times"
done
#!/bin/bash
for i in {1..5}
do
   echo "Welcome $i times"
done
#!/bin/bash
echo "Bash version ${BASH_VERSION}..."
for i in {0..10..2}
do 
     echo "Welcome $i times"
done

Also published on Medium.

Leave a Reply

Your email address will not be published. Required fields are marked *