Computing.Net > Forums > Unix > palindrone words

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

palindrone words

Reply to Message Icon

Name: DamMin
Date: April 2, 2005 at 19:27:26 Pacific
OS: unix
CPU/Ram: p133 64
Comment:

#!/bin/ksh
read word?'Enter the words to check> '
echo $word #shows words
echo $rword = "echo $word"
echo $rword| echo $word | sed "/\n/ !G;s/\(.)\(.*\n\)/&\2\1/;//D;s/.//"
if [[ $rword = $word ]] then
echo $word - Is a palindrome!
else
echo $word - Is not a palindrome!
fi

can't seem to make it work properly either any words entered are all a palindrome or all are not a palindrome



Sponsored Link
Ads by Google

Response Number 1
Name: gurubit
Date: April 4, 2005 at 00:37:29 Pacific
Reply:

Check the script below:
---------------------------

#!/bin/sh
l=0
cnt=1
tag=0
echo "Enter a Word?"
read str
l=`echo $str |wc -c`
l=`expr $l - 1`
lh=`expr $l / 2`
while [ $cnt -le $lh ]
do
c1=`echo $str|cut -c$cnt`
c2=`echo $str|cut -c$l`
if [ $c1 != $c2 ]
then
cnt=$lh
tag=1
fi
cnt=`expr $cnt + 1`
l=`expr $l - 1`
done
if [ $tag -eq 0 ]
then
echo "Word is Palindrome"
else
echo Word is not Palindrome
fi


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: palindrone words

Converting HTML, PostScript or PDF to Word Doc www.computing.net/answers/unix/converting-html-postscript-or-pdf-to-word-doc/1641.html

Searching for more then one word www.computing.net/answers/unix/searching-for-more-then-one-word/5027.html

Count no. of words of variable www.computing.net/answers/unix/count-no-of-words-of-variable/5233.html