Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

What is difference between shell and bash scripting?

947


How to use arguments in a script?

1045


What does $0 mean in shell script?

944


What does path stand for?

1011


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

1009


What are the different commands available to check the disk usage?

930


I want to create a directory such that anyone in the group can create a file and access any person's file in it but none should be able to delete a file other than the one created by himself.

976


What is wc in shell script?

940


What are the different types of variables used in shell script?

994


Write a shell script to get current date, time, user name and current working directory.

1038


Determine the output of the following command: name=shubham && echo ‘my name is $name’.

944


What is a shell environment?

944


‎What is a shell? · ‎Types of shell · ‎what is shell scripting?

934


What are the advantages of shell scripting?

991


How to write a function?

988