Saturday, April 1, 2017

Shell Scripting Tutorial for Beginners 15 - WHILE Loops


#!/bin/bash
# while loops
n=1

# first way
echo "----while loops------first way-------------------"
while [ $n -le 10 ]
do
    echo "$n"
    (( n++ ))
done


# second way
n=1
echo "----while loops------second way-------------------"
while (( $n <= 10 ))  
do
    echo "$n"
    (( ++n ))
done

# third way
n=1
echo "----while loops------third way-------------------"
while [ $n -le 10 ]
do
    echo "$n"
    n=$(( n+1 ))
done
output:
test@test:~/Desktop$ ./hello.sh 
----while loops------first way-------------------
1
2
3
4
5
6
7
8
9
10
----while loops------second way-------------------
1
2
3
4
5
6
7
8
9
10
----while loops------third way-------------------
1
2
3
4
5
6
7
8
9
10
test@test:~/Desktop$ 

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


Stuff I use to make videos

Windows notebook - http://amzn.to/2ADOPrW

Apple MacBook Pro - http://amzn.to/2AC0WG2

Microphone - http://amzn.to/2AC1kV0

notebook mouse - http://amzn.to/2BmeZ2d