write a shell script to identify the given string is
palindrome or not?

Answer Posted / manuswami

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 ?    87 Yes 35 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which scripting language is best for automation?

531


How do I read a .sh file?

529


How to pass an argument to a script?

592


What is echo $shell?

621


Why is shell scripting important?

571






What is the use of "$?" Sign in shell script?

617


Print a given number, in reverse order using a shell script such that the input is provided using command line argument only.

697


What are the different types of shell scripting?

532


What is a batch file used for?

559


What is sed in shell script?

568


What is echo in shell?

637


Can you write a script to portray how set –x works?

551


What is meant by dos operating system?

570


What is awk in shell scripting?

553


What is computer cli?

498