数值判断
NUM1=20
NUM2=10
if (($NUM1 > $NUM2)); then
echo "This $NUM1 greate $NUM2 !"
else
echo "This $NUM1 Little $NUM2 !"
fi
判断目录是否存在(如果不存在则创建该目录)
DIR=/tmp/20200603
if [ ! -d $DIR ];then
mkdir -p $DIR
echo -e "\033[32m目录创建成功!\033[0m"
else
echo -e "\033[32m目录已存在!\033[0m"
fi
判断文件是否存在,不存在创建,存在则输出内容
FILES=/tmp/test.txt
if [ ! -f $FILES ];then
echo "ok" >> $FILES
echo "文件创建成功!"
else
echo -e "\033[32m---------------------\033[0m"
echo "文件已存在,内容如下!"
cat $FILES
fi
判断数值是否符合条件
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 "考试不及格,补考!"
fi