Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi guys I'm getting this error message when running my KSH script:

./file.sh: line 16: syntax error at line 22: `done' unexpected

My code is as follows:

#!/bin/ksh
#

count=$#           #count is assigned num of parameters
num=$1             #assign parameter 1 to num

if test count -gt 9 #make sure theres only 9 numbers
    then
       echo "Only 9 parameters allowed"
       exit
fi


echo "Number of Parameters you passed: $count"
printf  "$num + \c"
sum=$1

while test $count -ge 1
     shift 1     #move numbers 1 to left
     num=$1      #assign new value to num
     printf "num + \c"
done

((sum = sum + num))

echo "$num = $sum"
share|improve this question
up vote 5 down vote accepted

You're missing the do keyword:

while ...; do
...
done
share|improve this answer
    
((sum += num)) also works – glenn jackman Mar 29 '14 at 20:08

You need a do after the while:

while test $count -ge 1
do
   ...
done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.