write a shell program to check wheather a given string is
pallindrome or not?

Answer Posted / goutamkumar

len=0
i=1
tag=0
echo -n "Enter a String: "
read str
len=`echo $str | wc -c`
len=`expr $len - 1`
halfLen=`expr $len / 2`

while [ $i -le $halfLen ]
do
c1=`echo $str|cut -c$i`
c2=`echo $str|cut -c$len`
if [ $c1 != $c2 ] ; then
i=$halfLen
tag=1
fi
i=`expr $i + 1`
len=`expr $len - 1`
done

if [ $tag -eq 0 ]
then
echo "String is Palindrome"
else
echo "String is not Palindrome"
fi

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is cmd a shell?

591


What language is bash written in?

557


What is shell chemistry?

534


What is shell environment?

544


What is batch file programming?

689






What is difference between shell and bash scripting?

541


How to find all the files modified in less than 3 days and save the record in a text file?

608


What does echo mean in scripting?

583


What is a boot block?

581


How to get the 3rd element/column from each line from a file?

683


What command needs to be used to take the backup?

528


What are the different commands available to check the disk usage?

489


Why are there shells on the beach?

589


Why do we write bin bash in shell scripts?

546


How do I stop script errors?

573