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 |
Is cmd a shell?
how to search for vowels a,e,i,o,u appearing in the same sequence in a file
What are the different types of commonly used shells on a typical linux system?
How would you print just the 25th line in a file using smallest shell script?
write a shell script to generate a alert ? like when ur birthday came then generate a alert ur birthday is today like that ?
What are the different types of variables used in shell script?
What are the different methods available to run a shell script?
How do I run a script from command prompt?
how to read systems current date and time
What is the syntax of "expr" command?
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
Hello all, This is my assignment on shell scripting, can anyone help me regarding this ? Create a shell script which connects to the database In second shell script include the first script for the DB connection Create a table (PRADEEP_DATA) with 2 columns (name, value) In Third shell script include the first script for the DB connection And insert/delete the values from the Table, by accepting input from the user This functionality should be a menu driven Program: 1) Insert to the database a. Name b. value 2)Delete from the database a.Name b.value Exception handling needs to be taken care.