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
What is the way to do multilevel if-else's in shell scripting?
What is the command to find out today's date?
How will you connect to a database server from linux?
What is the syntax of while loop in shell scripting?
What is sed in shell script?
Why is the use of shell script?
What can you do with powershell?
How important is shell scripting?
How will you copy a file from one machine to other?
How to open a read-only file in the shell?
How do I save a powershell script?
Where is bash history?
how to print the 2-d, 3-d arrays in unix shell script programs please answer thi questio to my mail venusaikumar@gmail.com
What is scripting autism?
How to get the 3rd element/column from each line from a file?