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
Which scripting language is best for automation?
How do I read a .sh file?
How to pass an argument to a script?
What is echo $shell?
Why is shell scripting important?
What is the use of "$?" Sign in shell script?
Print a given number, in reverse order using a shell script such that the input is provided using command line argument only.
What are the different types of shell scripting?
What is a batch file used for?
What is sed in shell script?
What is echo in shell?
Can you write a script to portray how set –x works?
What is meant by dos operating system?
What is awk in shell scripting?
What is computer cli?