shell 脚本程序

版权声明:本文为博主原创文章,未经博主允许不得转载。 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=$1

if [ -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
 

猜你喜欢

转载自blog.csdn.net/hxxjxw/article/details/88322461
今日推荐