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 ? | 410 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 |
Which is better perl or shell scripting?
What does $@ mean bash?
What is k shell?
What is MUTEX?
Is powershell a bash?
What is an sh file?
What is awk in shell script?
What is a boot block?
how can you execute the shell scripts?
Is SSO and SSL support BOXI?
What is the default shell of solaris?
What is the command for " how many shell is running in your system or how many shell supported by your system " ?.