【发布时间】:2017-04-02 22:30:49
【问题描述】:
我在 Vim 编辑器中为我的操作系统基础课程制作了一个 bash 脚本,我遇到了一个非常简单但令人沮丧的错误,我无法将变量加在一起并将总和设置为另一个变量。我尝试了多种格式来完成这项工作,但是它要么打印出每个值,要么打印出“:未找到”错误。这是我到目前为止的代码,我只是想将每个测试的值的总和设置为变量“finalgrade”并打印输出。
echo "Enter assignment mark (0 to 40): " ; read assignment
echo "Enter test1 mark (0 to 15): " ; read test1
echo "Enter test2 mark (0 to 15): " ; read test2
echo "Enter final exam mark (0 to 30): " ; read exam
finalgrade = $assignment + $test1 + $test2 + $exam
echo "Your final grade is : "$finalgrade
这是我运行它时得到的示例:
$ sh myscript
Enter assignment mark (0 to 40):
1
Enter test1 mark (0 to 15):
2
Enter test2 mark (0 to 15):
3
Enter final exam mark (0 to 30):
4
myscript: 5: myscript: finalgrade: not found
Your final grade is :
我希望最后一行是:
Your final grade is : 10
谢谢,
【问题讨论】:
标签: linux bash ubuntu arithmetic-expressions