GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Operating System  >  Shell Scripting
Go To First  |  Previous Question  |  Next Question 
 Shell Scripting  |  Question 22 of 47    Print  
Write a shell script to identify the given string is palindrome or not?

  
Total Answers and Comments: 10 Last Update: June 04, 2008     Asked by: athotaashok 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
February 21, 2006 22:42:05   #1  
Narayan Singh        

RE: write a shell script to identify the given string ...


print( Please enter a string );
$input_string <STDIN>;
chop($input_string);
$rev_string reverse($input_string);

if($input_string eq $rev_string){
print( The string is a palindrome );
}else{
print( The string is NOT a palindrome );
}


 
Is this answer useful? Yes | No
May 13, 2006 09:37:00   #2  
raj        

RE: write a shell script to identify the given string ...
this is perl. writing a shell script to do the job is difficult.
 
Is this answer useful? Yes | No
June 09, 2006 12:45:05   #3  
bwc        

RE: write a shell script to identify the given string ...
Actually you can do this..if [ -z echo $var | rev | sed -e s/^$var$// ]; then echo pali; else echo nopali; fi
 
Is this answer useful? Yes | No
July 06, 2006 06:10:22   #4  
Mukund        

RE: write a shell script to identify the given string ...

Hey frnds

Cant we write that using control statements like if!!!!

var hai

var1 `echo $var|rev`

if [ $var ! $var1 ] ; then
echo $var is not palindrome.
else
echo $var is palyndrome

fi


 
Is this answer useful? Yes | No
August 16, 2006 15:06:35   #5  
Nonsense        

RE: write a shell script to identify the given string ...
# bash-script: VAR lagerregalif [[ $VAR `echo $VAR | rev` ]]then echo palindromelse echo no palindromfi
 
Is this answer useful? Yes | No
November 20, 2006 20:15:15   #6  
vibs        

RE: write a shell script to identify the given string ...

echo -n 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 previoues number and current digit in rev
rev $( echo ${rev}${sd} )
done

if [ $on -eq $rev ];
then
echo Number is palindrome
else
echo Number is NOT palindrome
fi


 
Is this answer useful? Yes | No
December 12, 2006 07:20:01   #7  
Kunal        

RE: Write a shell script to identify the given string ...

!#/bin/sh

# To check whether the entered number is palindrome or not.

echo Enter a number:

read NUM1

echo $NUM1 > file.txt

NUM2 `rev file.txt`

if [ $NUM1 -eq $NUM2 ]; then

echo Entered Number $NUM1 is a palindrome.

else

echo Entered Number $NUM1 is not a palindrome.

fi


 
Is this answer useful? Yes | No
June 22, 2007 06:56:04   #8  
swaroopa Member Since: November 2005   Contribution: 2    

RE: Write a shell script to identify the given string ...
//Hi this is for strings

#!/bin/sh

echo "enter a string"
read str

var1 `echo $str|rev`
if [ $var1 ! $str ] ; then
echo "no pali"
else
echo "pali"
if

//this is for numbers

#!/bin/sh

echo "Enter a number to find for palindrome"
read num1
num $num1
i 0

while [ $num -gt 0 ]
do
i `expr $i * 10 + $num 10`
num `expr $num / 10`
done

if [ $i -eq $num1 ] ; then
echo "$num1 is a palindrome"
else
echo "$num1 is not a palindrome"
f

 
Is this answer useful? Yes | No
September 15, 2007 14:16:01   #9  
sudhir        

RE: Write a shell script to identify the given string ...
can u please explain the statement rev $(echo ${f}${f1}) please.
I did not understand how its working.

 
Is this answer useful? Yes | No
June 04, 2008 12:38:31   #10  
Vivek12 Member Since: June 2008   Contribution: 3    

RE: Write a shell script to identify the given string is palindrome or not?
echo enter a string
read string
len `expr length "$string"`
i $len
reverse ''
while [ $i -gt 0 ]
do
char `echo $string | cut -c $i`
reverse "$reverse$char"
i `expr $i - 1`
done
echo string:$string
echo reverse:$reverse
if [ $reverse $string ]
then
echo its a palindrome
else
echo its not a palindrome
fi

Hope this helps :)


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape