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

Explain about sourcing commands?

633


How do I run a shell script in powershell?

552


What is shell geeksforgeeks?

590


How do I save a powershell script?

553


How important is shell scripting?

543






Is it possible to substitute "ls" command in the place of "echo" command?

614


What language is used in terminal?

555


Write the syntax for "if" conditionals in linux?

591


What are the 3 standard streams in linux?

570


shell script for reverse the string

914


What is the meaning of $1 in shell script?

590


What is scripting used for?

553


How to calculate the number of passed arguments?

550


What happens on a system call?

558


i have 2 tables 4 colums table 1 respective values a1 6, a2 8,a3 9,a4 14 & table 2 respective values a1 6, a2 8, a3 9, a4 12. if compare 2 tables 3 colums values same then 4th column values 1)Qes diff >5 then (5 * diff value ) 2)Qes diff <5 the 5 3)Qes diff 5 then 5 print respective values..

1787