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


Please Help Members By Posting Answers For Below Questions

What is sed in shell script?

568


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.

2226


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.

2029


Give some situations where typing error can destroy a program?

722


What is a beat in a script?

541






What is wc in shell script?

557


What are zombie processes?

569


Explain about the exit command?

566


What is the use of .sh file?

598


How do you find out What is your shell?

590


How to use arguments in a script?

579


Is shell a part of kernel?

556


What is mac default shell?

614


write a shell script to check the failed jobs?

3954


What does chmod do?

570