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 the difference between bash and shell?
What does it mean to debug a script?
How can any user find out all information about a specific user like his default shell, real-life name, default directory, when and how long he has been using the system?
What are script files?
How do I open the shell prompt?
What are the different types of commonly used shells on a typical linux system?
How would you compare the strings in a shell script?
What is shell terminal?
How will you find the 99th line of a file using only tail and head command?
How do I start a shell script?
Explain about "s" permission bit in a file?
Print a given number, in reverse order using a shell script such that the input is provided using command line argument only.
What are the default permissions of a file when it is created?
What is an sh file?
What is subshell?