write a shell program to check wheather a given string is
pallindrome or not?
Answer Posted / 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 View All Answers
Determine the output of the following command: name=shubham && echo ‘my name is $name’.
What lives in a shell?
What is the command to find out today's date?
How to get the 3rd element/column from each line from a file?
What is basename in shell script?
What is the command to find out users on the system?
Write the syntax for "if" conditionals in linux?
Explain about gui scripting?
What is sed in shell script?
What are the advantages of shell scripting?
What is a shell script? Can you name some of its advantages?
How to check if the previous command was run successfully?
How do you create a shortcut in linux?
What are the disadvantages of shell scripting?
What is difference between bash and shell?