我得到了一个文件名txtGrade.txt
,其中包含以下内容:
Name Score
Nicki Minaj 60
我想通过 shell 脚本读取和计算文件中的每个人,并回答如下等级:
Name Score Grade
Nicki Minaj 60 C
条件为A>=80 , 79>=B>=70 ,69>=C>=60 , 59>=D>=50 , 49>=F
谢谢你帮助我 欣赏。
最佳答案
您需要的命令:
tail -n +2
打印文件第二行以后的内容。- 一个
case
statement 或 arithmetic expressions查看分数对应的年级。 读取带有名称和分数的行的循环:
while read -r first_name last_name score do [here $first_name etc. can be used] done
- 一个
case
statement查看分数对应的年级。 printf '%s %s\n' 'some text' "$some_variable"
打印“some text”,后跟一个空格,然后是$some_variable
的值,然后是换行符。
您还需要了解 quoting/word splitting 的一些知识.
关于linux - shell脚本中的成绩计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52586674/