编 写一个shell 脚本,检查给出的串是否为回文(palindrome)。
答:
l=`expr $len / 2`
ctr=1
flag=0
while test $ctr -le $l
do
a=`echo $str | cut -c$ctr`
b=`echo $str | cut -c$len`
if test $a -ne $b
then flag=1
break
fi
ctr=`expr $ctr + 1`
len=`expr $len - 1`
done
if test $flag -eq 0
then echo "String is palindrome"
else echo "String not a palindrome"
fi