Code In Tech - The Ultimate World of Computer Technology

Saturday, 12 May 2012

Shell script to check whether the given string is palindrome or not.

SOURCE CODE:

echo  “Enter the string:“
read str
l =`expr length $str`
a=l
while [ $a –lt -$l ]
do
     s1=`echo $str | cut –c $a`
     s2=`echo $str | cut –c $l`
     if [ $s1 !=  $s2 ]
     then

           echo “Given string is not Palindrom”
           break;
     else
           a =`expr $a + 1`
           l =`expr $l – 1`
     fi
done
if [ $a = $l ]
then
     echo “Given string is Palindrom”
fi

OUTPUT:

Enter the string:
AEHLE
Given string is not Palindrom  

No comments :

Post a Comment