Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


write a shell script to identify the given string is
palindrome or not?

Answers were Sorted based on User's Feedback



write a shell script to identify the given string is palindrome or not?..

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

write a shell script to identify the given string is palindrome or not?..

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

write a shell script to identify the given string is palindrome or not?..

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

write a shell script to identify the given string is palindrome or not?..

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

write a shell script to identify the given string is palindrome or not?..

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

write a shell script to identify the given string is palindrome or not?..

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

write a shell script to identify the given string is palindrome or not?..

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

Post New Answer

More Shell Script Interview Questions

What is shift command in shell script?

0 Answers  


How do I run a script on mac?

0 Answers  


I want to monitor a continuously updating log file, what command can be used to most efficiently achieve this?

0 Answers  


Why is it called a shell?

0 Answers  


What is wc in shell script?

0 Answers  


If you have a string "one two three", which shell command would you use to extract the strings?

5 Answers  


Hi, all Scripting professional. Q. I have written script1.sh and calling script2.sh in script1.sh file using bash shell as interpreter and my log in shell also bash shell.My code like Script1 #!/bin/bash echo "My script2 call" . script2.sh Here script2.sh file run successfully but when I have changed my interpreter bash to ksh like #!/bin/ksh Error are comming script2.sh command not found. Guid me how to call other script in our main script.

2 Answers  


What is .sh file in mac?

0 Answers  


Write a command sequence to find all the files modified in less than 2 days and print the record count of each.

0 Answers  


What is a command line shell?

0 Answers  


How does ls command work?

0 Answers  


What is the command for " how many shell is running in your system or how many shell supported by your system " ?.

3 Answers  


Categories