cant figure out the error in this script (adding numbers in a string) using ubantu shell

hii please help me this is the script

num=$1
sum=0

while [$num -ne 0]
do
x=`expr $num % 10`
sum=`expr $sum + $x`
num=`expr $num / 10`

done

echo "Summation is $sum"

it is giving error

pratyush@ubuntu:~$ sh shell.sh 123
shell.sh: 11: 123: not found
Summation is 0

please help!!!

while [ $num -ne 0 ]

(space after [ and space before ] )

1 Like

Also, you don't have to use expr here.

let X=num%10

Much more efficient.

1 Like

This worked thankyou very much :smiley: