This blog was opened by a team who love foss and is open for all those who love to contribute for foss development. All the foss lovers are most welcome to our blog. Take from it.Do not forget to contribute!
Monday, August 29, 2011
Integer and string Comparison in bash
Integer Comparison
There are 2 ways of comparing integers.
let's consider a and b as integer variables.
if [ "$a" -eq "$b" ] -checks weather $a equals to $b
if [ "$a" -ne "$b" ] -checks weather $a not equals to $b
if [ "$a" -gt "$b" ] or if(("$a" > "$b")) -checks weather $a is greater than $b
if [ "$a" -ge "$b" ] or if(("$a" >= "$b")) -checks weather $a is greater than or equal to $b
if [ "$a" -lt "$b" ] or if(("$a" < "$b")) -checks weather $a is less than $b
if [ "$a" -le "$b" ] or if(("$a" <= "$b")) -checks weather $a is less than or equal to $b
String Comparison
let's consider a and b as string variables.
if [ "$a" = "$b" ] -checks weather two strings are equal
if [ "$a" != "$b" ] -checks weather two strings are different
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment