Tuesday, January 1, 2013

String Comparison Operator in Shell Script

The below code snippet shows how to compare two strings

#!/bin/ksh
str1="Chidam";
str2="Chidam";
if [ "$str1" = "$str2" ] ; then
        echo -e "String str1 and str2 are same"
   echo -e "string1=$str1 and string2=$str2"
fi
str1="Chidam";
str2="Chidamk";
if [[ "$str1" != "$str2" ]] ; then
    echo -e "String str1 and str2 are not equal"
   echo -e "string1=$str1 and string2=$str2"
fi


OUTPUT :

-bash-3.2$ sh str_comp
String str1 and str2 are same
string1=Chidam and string2=Chidam
String str1 and str2 are not equal
string1=Chidam and string2=Chidamk

=  --> EQUAL OPERATOR
!= --> NOT EQUAL OPERATOR

No comments:

Post a Comment

Oracle Standard Package for Order Totals

  Purpose: Sometimes we need to show line-wise or complete order totals (Basic / Tax / Tax+Basic) in reports. Oracle provides a standard...