Written by Sai Sandeep Thota on April 14, 2013 in Programming > Shell

Shell Script to Perform String Comparison

GET ALERTS:

Get our Latest updates delivered to your mailbox!

This script is used to check whether two given strings are equal or not. We can do this by simple comparison if [ $string1 -eq $string2 ].

echo "Enter First String:"
read string1
echo "Enter Second String:"
read string2
if [ $string1 -eq $string2 ]
then
	echo "Strings are equal!"
else
	echo "Strings are not equal!!"
fi

Output:
strings

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: