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 |
What are different types of shell?
How to customise the other shell?
How will you find the 99th line of a file using only tail and head command?
Determine the output of the following command: name=shubham && echo ‘my name is $name’.
Write a shell script that adds two numbers if provided as the command line argument and if the two numbers are not entered throws an error message.
What can you do with powershell?
What are the various stages of a linux process it passes through?
What are the advantages of using shell scripts?
How to print some text on to the screen?
What is a shell made of?
Hi Friends, I am currently Undergoing Course On Testing.I am Planning To Keep Fake Resume.Can any One tell me the ways to Prepare i.e, Real Time experience For Manual Testing. With Regards, Vikram
RAM one table colums a1,a2,a3,a4 respective values 2,4,7,8 KRISH one table colums a1,a2,a3,a4 respective values 3,4,6,9 IN RAM & KRISH a4 column if comparing values RAM A4 - KRISH A4 ( 8-9 =1 THEN print 5 or (RAM) a4 value 10 KRISH a4 values 2 then 10 -2 =8 print 5*8=40 or diff 5 print same