BASH Script to Check if a number is Armstrong or Not

Posted by atif089 on Stack Overflow See other posts from Stack Overflow or by atif089
Published on 2010-06-16T08:20:13Z Indexed on 2010/06/16 8:22 UTC
Read the original article Hit count: 364

Filed under:
|
|

Hi, I was writing a script to check if a number is Armstrong or not. This is my Code

echo "Enter Number"
read num
sum=0
item=$num
while [ $item -ne 0 ]
do
rem='expr $item % 10'
cube='expr $rem \* $rem \* $rem'
sum='expr $sum + $cube'
item='expr $item / 10'
done
if [ $sum -eq $num ]
then
echo "$num is an Amstrong Number"
else
echo "$num is not an Amstrong Number"
fi

After I run this script,

$ ./arm.sh

I always get this error

./arm.sh: line 5: [: too many arguments ./arm.sh: line 12: [: too many arguments

I am on cygwin.

© Stack Overflow or respective owner

Related posts about bash

Related posts about unix