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
State the advantages of shell scripting?
How do I save a powershell script?
how to get part of string variable with echo command only?
What is the default ubuntu terminal?
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 are types of shells?
How do I run a shell script in powershell?
Give some situations where typing error can destroy a program?
Devise a script that takes file name as arguement(which must present in the current directory)and locates from your home directory tree all thpath names of its links.Then mail the list to self.
What are the different types of commonly used shells on a typical linux system?
How to print all the arguments provided to the script?
How to print pid of the current shell?
wats the deinitions for shell utility and filter?
Explain how you Automate your application using Shell scripting.
How to redirect both standard output and standard error to the same location?