Saturday, March 14, 2015

String comparison

Algorithm
Step 1 : Start
Step 2 : Read strings str1 and str2
Step 3 : If str1 = str2 then
Print "Strings are the same"
Step 3.1 : else
Print "Strings are distinct"
Step 4 : Stop

Program (strcomp.sh)
echo -n "Enter the first string : "
read s1
echo -n "Enter the second string : "
read s2

if [ $s1 == $s2 ]
then
echo "Strings are the same"
else
echo "Strings are distinct"
fi

Output
[vijai@localhost decision]$ sh strcomp.sh
Enter the first string : ece-a
Enter the second string : ECE-A
Strings are distinct

No comments:

Post a Comment