write a shell program to check wheather a given string is
pallindrome or not?

Answers were Sorted based on User's Feedback



write a shell program to check wheather a given string is pallindrome or not?..

Answer / mahesh gupta

this script is written for bash :
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 ?    21 Yes 6 No

write a shell program to check wheather a given string is pallindrome or not?..

Answer / ishita sen

echo Enter the string
read s
echo $s > temp
rvs="$(rcs temp)"
if [ $s = $rcs ]
then
echo "it is palindrome"
else
echo " it is not"
fi

Is This Answer Correct ?    11 Yes 5 No

write a shell program to check wheather a given string is pallindrome or not?..

Answer / goutamkumar

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 ?    6 Yes 1 No

write a shell program to check wheather a given string is pallindrome or not?..

Answer / sudhir

#!/bin/ksh

i=1
tag=0

print -n "Enter a String:"
read str
len=`echo $str | wc -c`
if [[ $len -eq 1 ]]
then
print "Enter a valid string"
exit 2;
fi

let len=len-1
let halflen=len/2;

while [[ $i -le $halflen ]]
do
c1=`echo $str | cut -c $i`
c2=`echo $str | cut -c $len`

if [[ $c1 != $c2 ]]
then
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 ?    0 Yes 0 No

Post New Answer

More Shell Script Interview Questions

whta is the use of "exec" command?

1 Answers  


How to get the 3rd element/column from each line from a file?

0 Answers  


There are three departments A,B and C.Write a query to display the names of all the persons( in departments other than A) who are paid higher than the person receiving the lowest salary in DEPT A

1 Answers   Wipro,


Is scripting and coding the same thing?

0 Answers  


How will you pass and access arguments to a script in linux?

0 Answers  






How to write an Auto scripting for deleting old files using shell script and made a cron job to run on daily basis

1 Answers  


What is awk in shell scripting?

0 Answers  


What is a scripting language simple definition?

0 Answers  


what is this line in the shell script do ?#!/bin/ksh

5 Answers  


What is the first line in every perl script called?

0 Answers  


What does it mean by #!/Bin/sh or #!/Bin/bash at the beginning of every script?

0 Answers  


What is difference between bash and shell?

0 Answers  


Categories