苏州网站建设多少钱外贸营销网站建设
思维导图
作业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 ]
thenecho "不及格"
elif [ "$score" -ge 60 -a "$score" -lt 70 ]
thenecho "D"
elif [ "$score" -ge 70 -a "$score" -lt 80 ]
thenecho "C"
elif [ "$score" -ge 80 -a "$score" -lt 90 ]
thenecho "B"
elif [ "$score" -ge 90 -a "$score" -lt 100 ]
thenecho "A"
fi
作业2
提示并输入一个文件
判断文件是否存在
如果存在,判断文件是否为普通文件
如果是,则将“hello world”写入到该文件中 echo"hello world">>$FILE
如果条件不成立,给出相关描述信息
#!/bin/bash read -p "请输入一个文件:" file
if [ -e $file ]
thenecho "文件存在"if [ -f $file ]thenecho "文件为普通文件"echo "hello world" >> $filecat $fileelseecho "文件不是普通文件"fi
elseecho "文件不存在"
fi
刷题