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
How do I run a script on mac?
Can shell script run on windows?
What is shell and shell script?
How do I run a powershell script?
How do you debug a script?
How do I set bash as default shell mac?
What is the default shell of solaris?
How to check if a directory exists?
What does $@ mean bash?
Is shell a scripting language?
How to print pid of the current shell?
How can we find the process name from its process id?
What is in a script?
When should shell programming/scripting not be used?
What is ms powershell?