Ksh

KSH while 循環導致問題

  • March 29, 2014

大家好,我在執行我的 KSH 腳本時收到此錯誤消息:

./file.sh:第 16 行:第 22 行的語法錯誤:“完成”意外

我的程式碼如下:

#!/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"

您缺少do關鍵字:

while ...; do
...
done

你需要一個do之後while

while test $count -ge 1
do
  ...
done

引用自:https://unix.stackexchange.com/questions/122165