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
What is bash coding?
What can you do with powershell?
how to print the 2-d, 3-d arrays in unix shell script programs please answer thi questio to my mail venusaikumar@gmail.com
What is shell environment?
Can you write a script to portray how set –x works?
Determine the output of the following command: [ -z “” ] && echo 0 || echo 1
What can scripts do?
What is the first line of a shell script called?
How do I save a powershell script?
What is bash eval?
What is the syntax of "nested if statement" in shell scripting?
What language is shell scripting?
What does path stand for?
What is the difference between bash and shell?
How do I stop script errors?