尝试四处搜索并找不到我的问题的直接答案,因为那里的所有其他代码似乎都在做我正在做的事情。我正在做一个 shell 脚本练习来计算一个类的平均值,我已经使用我们的参考脚本做到了这一点,但是我收到了关于语法的错误(代码底部的错误)
#!/bin/bash
avg=0
temp_total=0
number_of_args=$#
# First see the sufficient cmd args
if [ $# -lt 2 ] ; then
echo -e "Oops! I need at least 2 command line args to calculate an average\n"
echo -e "Syntax: $0: number1 number2 ... numberN\n"
echo -e "Example:$0 5 4\n\t$0 56 66 34"
exit 1
fi
# now calculate the average of the numbers given on command line as cmd args for i in $*
do
# addition of all …Run Code Online (Sandbox Code Playgroud)