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
How to pass an argument to a script?
shell script for reverse the string
Using set -A write a script to print the output of the ls command in 5 columns with two spaces between each column. Pretend that ls does not have multicolumn output.
How to print pid of the current shell?
What does the sh command do?
What is a shell in operating system?
How do scripts work?
What is k shell?
I want to monitor a continuously updating log file, what command can be used to most efficiently achieve this?
What does $$ mean in shell script?
What is basename in shell script?
When should shell programming/scripting not be used?
What is awk script?
How do I open the shell in cmd?
Which is better perl or shell scripting?