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 difference between shell and bash scripting?
How to use arguments in a script?
What does $0 mean in shell script?
What does path stand for?
Is it possible to substitute "ls" command in the place of "echo" command?
What are the different commands available to check the disk usage?
I want to create a directory such that anyone in the group can create a file and access any person's file in it but none should be able to delete a file other than the one created by himself.
What is wc in shell script?
What are the different types of variables used in shell script?
Write a shell script to get current date, time, user name and current working directory.
Determine the output of the following command: name=shubham && echo ‘my name is $name’.
What is a shell environment?
What is a shell? · Types of shell · what is shell scripting?
What are the advantages of shell scripting?
How to write a function?