write a shell script to identify the given string is
palindrome or not?
Answers were Sorted based on User's Feedback
Answer / abhijeet chavan (cts)
set -x
input_string=$1
if [ -z "$input_string" ] ; then
echo "Please enter a Text along with the script name\n"
exit
fi
reversed_string=$(rev $input-string)
if [ "$input_string" -eq "$reverse_string" ] ; then
echo "The String $input_String is a Palindrome"
else
echo "This string is not a palindrome"
fi
| Is This Answer Correct ? | 49 Yes | 51 No |
Answer / onkar
# Check wheather given number is Palindrome or Not ?
# for ex- 121 -palindrome ,123 -Not palindrome
echo "Enter Number\n"
read no
n1=$no
rev=0
while [ $n1 -ne "0" ]
do
rem=`expr $n1 % "10"`
n1=`expr $n1 / "10"`
rev=`expr $rem + $rev \* "10"`
done
if [ $no -eq $rev]
then
echo Palindrome
else
echo Not Palindrome
fi
| Is This Answer Correct ? | 14 Yes | 16 No |
Answer / purbasha jana
echo "Enter number : "
read n
# store single digit
sd=0
# store number in reverse order
rev=""
# store original number
on=$n
while [ $n -gt 0 ]
do
sd=$(( $n % 10 )) # get Remainder
n=$(( $n / 10 )) # get next digit
# store previous number and current digit in reverse
rev=$( echo ${rev}${sd} )
done
if [ $on -eq $rev ];
then
echo "Number is palindrome"
else
echo "Number is NOT palindrome"
fi
| Is This Answer Correct ? | 10 Yes | 12 No |
Answer / sunny garg
echo "Enter the string"
read s
echo "$s -gt temp"
rvs="$(rev temp)"
if [ $s -eq $rvs ]
then
echo "it is palindrome"
else
echo " it is not"
fi
| Is This Answer Correct ? | 4 Yes | 6 No |
Answer / akshay telang
#! /usr/bin/ksh
string=$1
str1=$1
pal=""
typeset -R1 last
while ((${#string})) ; do
last=$string
pal=${pal}${last}
if ((${#string} > 1)) ; then
typeset -L$((${#string}-1)) oneLess=$string
string=$oneLess
else
string=
fi
done
if [ "$str1" == "$pal" ]
then
echo "String is a Palindrome"
else
echo "String is not a Palindrome"
fi
| Is This Answer Correct ? | 24 Yes | 28 No |
Answer / shashank gonte
#!/bin/sh
if [ $# -eq 1 ] #accept input through as parameter to #
command
then
echo $1 > temporary.txt #store input to a file
if [ `cat temporary.txt` = `rev temporary.txt` ]
then
echo -e "\n\n$1 is pelindrome\n\n"
else
echo -e "\n\n$1 is not pelindrome\n\n"
fi
rm temporary.txt #remove temporary created file
else #input validation for only one parameter accepted
echo -e "\n\ninvalid no of argument please enter
only one string argument\n\n"
exit 0
fi
| Is This Answer Correct ? | 0 Yes | 4 No |
Answer / dhyan@addiction
# PROGRAM TO FIND OUT WHETHER THE A INPUTED STRING IS
PALINDROME OR NOT.
echo -n "Please enter a string: "
read input_string
echo $input_string >> temp
reversed_string="$(rev temp)"
if [ $input_string = $reversed_string ]
then
echo -e "The string$input_string is palindrome\n"
else
echo -e "This string is not palindrome\n"
fi
rm temp #to use same file again and again
| Is This Answer Correct ? | 2 Yes | 6 No |
What is option in shell script?
What is the difference between a shell variable that is exported and the one that is not exported?
How will you emulate wc –l using awk?
What is shell geeksforgeeks?
What is the conditional statement in shell scripting?
What are the additional egrep symbols?
how to search for vowels a,e,i,o,u appearing in the same sequence in a file
What happens when you type ls?
Is shell scripting useful?
Is shell scripting a language?
What is a program shell?
how can you execute the shell scripts?