write a shell script to identify the given string is
palindrome or not?
Answers were Sorted based on User's Feedback
Answer / rag sagar.v
echo Enter the string
read s
echo $s > temp
rvs="$(rev temp)"
if [ $s = $rvs ]
then
echo "it is palindrome"
else
echo " it is not"
fi
Is This Answer Correct ? | 409 Yes | 149 No |
Answer / 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 |
Answer / gaurav shah
clear
echo enter a string
read a
b=`expr $a | wc -c`
b=`expr $b - 1`
echo number of letter=$b
while test $b -gt 0
do
e=`expr $a | cut -c $b`
d=$d$e
b=`expr $b - 1`
done
echo the reversed string is :$d
if test $a = $d
then
echo it is a palindrome
else
echo it is not a palindrome
fi
Is This Answer Correct ? | 54 Yes | 21 No |
Answer / siva
echo "PALINDROME NUMBER"
echo "ENTER THE NUMBER :"
read n
n1=$n
rev=0
while [ $n1 -ne 0 ]
do
rem=`expr $n1 % 10`
n1=`expr $n1 / 10`
rev=`expr $rem + $rev \* 10`
done
if [ $n -eq $rev ]
then
echo $n is a Palindrome Number
else
echo $n is not a Palindrome Number
fi
PALINDROME NUMBER
ENTER THE NUMBER :
121
121 is a Palindrome Number
$sh palno.sh
PALINDROME NUMBER
ENTER THE NUMBER :
123
123 is not a Palindrome Number
Is This Answer Correct ? | 24 Yes | 7 No |
Answer / gaurav shah.ait
tput clear
echo -e "Enter String :- \c"
read str
len=`expr $str|wc -m `
len=`expr $len - 1`
len1=`expr $len `
echo -e "Reverse String :- \c"
while [ $len -ne 0 ]
do
s1=` expr $str|cut -c$len `
echo -e "$s1\c "
len=` expr $len - 1 `
done
len=`expr $str|wc -m `
len=`expr $len - 1`
echo ""
n=1
flag=0
while [ $len -ne 0 ]
do
fst=` expr $str|cut -c$n `
lst=` expr $str|cut -c$len `
len=` expr $len - 1 `
n=` expr $n + 1`
if test $fst != $lst
then
flag=1
fi
done
if test $flag = 1
then
echo "Given String Is Not Palindrome"
else
echo "Given String Is Palindrome"
fi
Is This Answer Correct ? | 16 Yes | 9 No |
Answer / sathya
echo "enter a string"
read str
rev=`expr $str|rev`
if [ $rev = $str ]
then
echo "the given string is palindrome"
else
echo "the given string is not palindrome"
fi
Is This Answer Correct ? | 20 Yes | 14 No |
Answer / lekhrajdeshmukh
n=$1
a=0
b=0
while [ $n -gt 0 ]
do
b=$(( $n % 10 ))
a=$(( ($a * 10) + $b ))
n=$(( $n /10 ))
done
if [ $a -eq $1 ]
then
echo "$1 number is palindrome number"
else
echo "$1 is not an palindrome number"
fi
Is This Answer Correct ? | 56 Yes | 53 No |
Answer / hemanth kadham
echo "PALINDROME NUMBER"
echo "ENTER THE NUMBER :"
read n
n1=$n
rev=0
while [ $n1 -ne 0 ]
do
rem=`expr $n1 % 10`
n1=`expr $n1 / 10`
rev=`expr $rem + $n1 \* 10`
done
if [ $n -eq $rev ]
then
echo $n is a Palindrome Number
else
echo $n is not a Palindrome Number
fi
PALINDROME NUMBER
ENTER THE NUMBER :
121
121 is a Palindrome Number
$sh palno.sh
PALINDROME NUMBER
ENTER THE NUMBER :
123
123 is not a Palindrome Number
Is This Answer Correct ? | 5 Yes | 4 No |
Answer / kirtiranjan sahoo
read -p "Enter a string : " st
rvs=`echo $st | rev`
if [ $st == $rvs ]
then
echo "Palindrome"
else
echo "Not Palindrome"
fi
Is This Answer Correct ? | 2 Yes | 3 No |
Answer / prasath
echo"to check whether given string is palindrom or not"
echo"Enter the string"
read str
Len=$(echo "$str"| wc -c
while [$len -gt 0]
do
ch=$(echo "$str"| cut -c $len)
echo -n "$ch"
s1=$s1$ch
Len =`expr $len -1`
done
echo""
if [$s1 != $str]
Then
echo "Tha string is not palindrom"
else
echo"The string is palindrom"
fi
Is This Answer Correct ? | 0 Yes | 1 No |
How do I start a shell script?
Is scripting and coding the same thing?
How to print all the arguments provided to the script?
what is the meaning of First line of shell script ,what is meaning of #! pleas explain brifly
How do I run a .sh file?
What's the difference between scripting and coding?
When you login to a c shell, which script would be run first?
what do u mean by $#,$* in unix programming?
What does the sh command do?
What is a scripting language simple definition?
how to print the matrix form of 2-d, 3-d arrays in unix c shell scripts ?
how to get part of string variable with echo command only?