write a shell program to check wheather a given string is
pallindrome or not?

Answer Posted / sudhir

#!/bin/ksh

i=1
tag=0

print -n "Enter a String:"
read str
len=`echo $str | wc -c`
if [[ $len -eq 1 ]]
then
print "Enter a valid string"
exit 2;
fi

let len=len-1
let halflen=len/2;

while [[ $i -le $halflen ]]
do
c1=`echo $str | cut -c $i`
c2=`echo $str | cut -c $len`

if [[ $c1 != $c2 ]]
then
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 ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do I open a jshell in cmd?

602


What are the four fundamental components of every file system on linux?

1168


What is a shell script in windows?

590


What exactly is a shell?

608


What are the advantages of using shell scripts?

589






one folder contains lot of students name but I want to fetch hello with every student name individually using shell script

522


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..

1795


How do I run a .sh file on mac?

682


Is shell a scripting language?

576


I have to write Shells (Linux + Unix)for publishing packages and reports. Is it possible ? What are the differents executable programs ineed to call ?

1686


how will you find the total disk space used by a specific user?

584


Is bash an operating system?

548


What is eval in shell script?

653


What is shell chemistry?

542


What is the use of break command?

590