write a shell script to identify the given string is
palindrome or not?

Answer Posted / gaurav shah.ait

tput clear

echo -e "Enter String :- \c"
read str
len=`expr $str|wc -m `
len=`expr $len - 1`
len1=`expr $len `
echo -e "Reverse String :- \c"
while [ $len -ne 0 ]
do
s1=` expr $str|cut -c$len `
echo -e "$s1\c "
len=` expr $len - 1 `
done
len=`expr $str|wc -m `
len=`expr $len - 1`
echo ""
n=1
flag=0
while [ $len -ne 0 ]
do
fst=` expr $str|cut -c$n `
lst=` expr $str|cut -c$len `
len=` expr $len - 1 `
n=` expr $n + 1`

if test $fst != $lst
then
flag=1
fi
done
if test $flag = 1
then
echo "Given String Is Not Palindrome"
else
echo "Given String Is Palindrome"
fi

Is This Answer Correct ?    16 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is shell environment?

544


wats the deinitions for shell utility and filter?

1837


What is an sh file?

554


Which shell is the best?

572


What is a command line shell?

561






How do I run a .sh file?

610


Where is bash history?

504


What happens when you type ls?

556


What is echo in shell?

633


When should shell programming/scripting not be used?

588


Print a given number, in reverse order using a shell script such that the input is provided using command line argument only.

693


What are the advantages of using shell scripts?

575


What is the default shell of solaris?

565


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.

2168


Explain about gui scripting?

620