Shell script to print numbers from 1 to 100

Let's write a shell script to print numbers 1 to 100.

This will help us to understand the basics of looping statements in shell script.




Print numbers 1 to 100 using while loop - Shell Script

#shell script to print numbers 1 to 100

i=1
while [ $i -le 100 ]
do
    echo $i
    i=$(($i+1))
done

-le stands for less than or equal to.




Same program using expr

#shell script to print numbers 1 to 100
#using while loop and expr

i=1
while [ $i -le 100 ]
do
    echo $i
    i=`expr $i + 1`
done



Print numbers 1 to 100 using for loop - Shell Script

#shell script to print numbers 1 to 100
#using for loop

for((i=1;i<=100;i++))
do
    echo $i
done

Useful Resources

To learn more shell script examples, you can visit the link