[root@rhel1 ~]# cat test2.sh #!/bin/bash #program for -gt comparing b=100 echo "enter value grater than 100" read a if [ $a -gt $b ] then echo "Very Good" else echo "You are naughty" fi
4. -le operator
This bash compare numbers operator will check the values for less than or equal . If its less than or equal then it return value 0.
#program for -le comparing b=5 echo "enter value less than or equal to 5" read a if [ $a -le $b ] then echo "You like weekdays" else echo "You are week end fan!!!!" fi [root@rhel1 ~]#
5. -lt operator
This bash compare numbers operator will check the values for less than. If it’s less than, then it return value 0.
[root@rhel1 ~]# cat test4.sh #!/bin/bash #program for -lt comparing b=0 echo "enter number with minus sign" read a if [ $a -lt $b ] then echo "Oho You are honest!!!" else echo "Go Away" fi [root@rhel1 ~]#
6. -ne operator
This bash compare numbers operator will check the values are not equal. If its not equal it return value 0.
[root@rhel1 ~]# cat test5.sh #!/bin/bash #program for -ne comparing b=0 echo "Please enter any non zero value" read a if [ $a -ne $b ] then echo "Very Nice!!!" else echo "Oh My god You have entered Zero value" fi [root@rhel1 ~]#
Execution:
[root@rhel1 ~]# sh test5.sh Please enter any non zero value 2 Very Nice!!! [root@rhel1 ~]# sh test5.sh Please enter any non zero value 0 Oh My god You have entered Zero value
To Know more about for loops,
To know more about while loops.
Pages: 1 2
Leave a Reply