简体   繁体   中英

I am getting error “unary operator expected”

I am getting the error unary operator expected at line no 5 and line 11 . please help to resolve this problem.

echo ”enter the number”
read n
q=$n
a=0
while [ $q – gt 0 ]
do
  r= `expr $q % 10 `
  q= `expr $q / 10 `
  a=`expr $a + $r /* $r /*$r `
  done
  if [ $a=$n ]
  then
    echo “the number $n is armstrong number”
  else
    echo “the number $n is not armstrong number”
  fi
done

At line number 9 you have used the forward slash instead of backslash. Also the loop end should be above the 'if' condition. If condition also should be modified as -eq .

echo ”enter the number”
read n
q=$n
a=0
while [ $q -gt 0 ]
do
    r=`expr $q % 10`
    q=`expr $q / 10`
    a=`expr $a + $r \* $r \* $r`
done

if [ $a -eq $n ]
then
    echo “the number $n is armstrong number”
else
    echo “the number $n is not armstrong number”
fi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM