write a shell script to identify the given string is
palindrome or not?
Answer Posted / manuswami
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 ? | 87 Yes | 35 No |
Post New Answer View All Answers
What is sed in shell script?
write a shell script to emulate the Id command of PRIMOS which lists files and directories. It list files first with a header FILES and then directories with a header DIRECTORIES. This command has several options. The main ones are. -file select files only -dir select directories only -reverse sort in reverse order -no_header put no header on the output -brief output the header only -size display the size of each file -help display Id´s syntax and options.
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.
Give some situations where typing error can destroy a program?
What is a beat in a script?
What is wc in shell script?
What are zombie processes?
Explain about the exit command?
What is the use of .sh file?
How do you find out What is your shell?
How to use arguments in a script?
Is shell a part of kernel?
What is mac default shell?
write a shell script to check the failed jobs?
What does chmod do?