0304作业
- 游戏开发
 - 2025-09-11 09:36:02
 

思维导图
作业1
在终端提示输入一个成绩,通过shell判断该成绩的等级 [90,100]:A [80, 90):B [70, 80):C [60, 70): D [0,60):不及格
#!/bin/bash read -p "请输入成绩:" score if [ "$score" -ge 0 -a "$score" -lt 60 ] then echo "不及格" elif [ "$score" -ge 60 -a "$score" -lt 70 ] then echo "D" elif [ "$score" -ge 70 -a "$score" -lt 80 ] then echo "C" elif [ "$score" -ge 80 -a "$score" -lt 90 ] then echo "B" elif [ "$score" -ge 90 -a "$score" -lt 100 ] then echo "A" fi作业2
提示并输入一个文件 判断文件是否存在 如果存在,判断文件是否为普通文件 如果是,则将“hello world”写入到该文件中 echo"hello world">>$FILE 如果条件不成立,给出相关描述信息
#!/bin/bash read -p "请输入一个文件:" file if [ -e $file ] then echo "文件存在" if [ -f $file ] then echo "文件为普通文件" echo "hello world" >> $file cat $file else echo "文件不是普通文件" fi else echo "文件不存在" fi刷题