write a shell program to check wheather a given string is
pallindrome or not?
Answer Posted / 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 |
Post New Answer View All Answers
What is a shell in operating system?
What are the various stages of a linux process it passes through?
How do I read a .sh file?
How do you find out What is your shell?
What does $@ mean bash?
How to use arguments in a script?
What is bourne shell scripting?
What is the significance of the shebang line in shell scripting?
What is a boot block?
In my bash shell I want my prompt to be of format '$"present working directory":"hostname"> and load a file containing a list of user-defined functions as soon as I log in, how will you automate this?
What is the purpose of scripting?
How does path variable work?
How to print all array elements and their respective indexes?
Explain about shebang?
What is the use of echo in shell script?