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


Please Help Members By Posting Answers For Below Questions

State the advantages of shell scripting?

592


How do I save a powershell script?

555


how to get part of string variable with echo command only?

589


What is the default ubuntu terminal?

616


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?

636






What are types of shells?

543


How do I run a shell script in powershell?

554


Give some situations where typing error can destroy a program?

722


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.

1705


What are the different types of commonly used shells on a typical linux system?

550


How to print all the arguments provided to the script?

553


How to print pid of the current shell?

602


wats the deinitions for shell utility and filter?

1841


Explain how you Automate your application using Shell scripting.

1847


How to redirect both standard output and standard error to the same location?

627