版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hxxjxw/article/details/88322461
1、判断文件是否已经存在,存在输出内容,不存在创建并添加一句话
#!/bin/bash
FILES=no/test.txt
if [ ! -f $FILES ];then
echo "OK" >> $FILES
else
echo -e "\033[32m---------------------\033[1m"
cat $FILES
fi
2、if else语句判断分数大小#!/bin/bash
scores=$1if [ -z $scores ];then
echo "usage:{ $0 60|80. }"
exit
fi
if [[ $scores -gt 85 ]];then
echo "very good!";
elif [[ $scores -gt 75 ]];then
echo "good!";
elif [[ $scores -gt 60 ]];then
echo "pass!";
else
echo "no pass"
fi