SHELL SCRIPT TO FIND POLYNDROME | URDINESH

Software Programming, Tutorials, Interview Preparations,Stock Market,BSE/NSE, General informations

Sunday, July 19, 2015

SHELL SCRIPT TO FIND POLYNDROME

Polyndrome Or Not:

count=`echo $1 | wc -c`
count=`echo $count - 1|bc`
echo "length of the given string is:"$count
while [ $count -gt 0 ]
do
rev1=`echo $1 | cut -b $count`
rev2=$rev2$rev1
count=`expr $count - 1`
done
if [ $rev2 = $1 ]
then
echo "string is palindrome"
else
echo "string is not palindrome"
fi

















OUTPUT:
 [localhost ~]$ sh pol.sh madam
Length of The Given String is:5
String is Palindrome
[localhost ~]$ sh pol.sh sir
Length of The Given String is:3
String is Not Palindrome
[localhost ~]$ sh pol.sh malayalam
Length of The Given String is:9
String is Palindrome
[localhost ~]$

No comments:

Post a Comment

Thanks for your valuable comments

Followers