itsReZa
itsReZa

Reputation: 17

I don't know why I keep on getting this error " syntax error near unexpected token `do' "

I don't understand why this isn't running. I looked up the syntax for while loops and I think I'm doing it right. Help, please.

#!/bin/bash
#

x=0 # init x=0
i=1
while[ $i -le $1 ] # while(i<=userInput)
do
        s=`expr $i \* $i` # s=i*i
        x=`expr $s + $x`
        i=`expr $i + 1` # i=i+1
done

echo x=$x

Upvotes: 0

Views: 37

Answers (1)

SergiyKolesnikov
SergiyKolesnikov

Reputation: 7815

You need a space between while and [ $i -le $1 ].

Upvotes: 1

Related Questions