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

What is a shell in operating system?

593


What are the various stages of a linux process it passes through?

630


How do I read a .sh file?

532


How do you find out What is your shell?

592


What does $@ mean bash?

670






How to use arguments in a script?

585


What is bourne shell scripting?

533


What is the significance of the shebang line in shell scripting?

533


What is a boot block?

586


In my bash shell I want my prompt to be of format '$"present working directory":"hostname"> and load a file containing a list of user-defined functions as soon as I log in, how will you automate this?

640


What is the purpose of scripting?

584


How does path variable work?

549


How to print all array elements and their respective indexes?

512


Explain about shebang?

624


What is the use of echo in shell script?

545