我正在尝试为一个类编写我的第一个 shell 脚本。目标是将整数列表作为命令行参数并显示它们的平方和平方和。我收到一个错误,即找不到参数。
这是给出未找到参数的错误的部分:
sumsq=0 #sum of squares
int=0 #Running sum initialized to 0
count=0 #Running count of numbers passed as arguments
while [ $# != 0 ]
do
numbers[$int]=`expr $1` #Assigns arguments to integers
let square=`expr $1*$1` #Operation to square arguments
squares[$int]=$square #Calc. square of each argument
sumsq=`expr $sumsq + $square` #Add square to total
count=`expr $count + 1` #Increment count
shift #Remove the used argument
int=`expr $int + 1` #Increment to next argument
done
我正在使用破折号外壳。