Linux shell_IF判断
数值判断
#!/bin/bash NUM1=20 NUM2=10 if (($NUM1 > $NUM2)); then echo "This $NUM1 greate $NUM2 !" else echo "This $NUM1 Little $NUM2 !" fi
判断目录是否存在,如果不存在则创建该目录
#!/bin/bash DIR=/tmp/20200603 if [ ! -d $DIR ];then mkdir -p $DIR echo -e "\033[32m目录创建成功!\033[0m" else echo -e "\033[32m目录已存在!\033[0m" fi
判断文件是否存在,不存在创建,存在则输出内容
#!/bin/bash FILES=/tmp/test.txt if [ ! -f $FILES ];then echo "ok" >> $FILES echo "文件创建成功!" else echo -e "\033[32m---------------------\033[0m" echo "文件已存在,内容如下!" cat $FILES fi
判断数值是否符合条件
#!/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 "考试不及格,补考!" fi ———————————————— 版权声明:本文为CSDN博主「TG_天道」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/u013915081/article/details/106661313
相关推荐
farwang 2020-11-25
星愿心愿 2020-11-24
tianhuak 2020-11-24
zhjn0 2020-11-24
昭君出塞 2020-11-23
bluecarrot 2020-11-23
linuxwcj 2020-10-21
以梦为马不负韶华 2020-10-20
彼岸随笔 2020-10-20
yutou0 2020-10-17
applecarelte 2020-10-16
ourtimes 2020-10-16
waterhorse 2020-09-19
MRFENGG 2020-11-11
rainandtear 2020-10-30
kyssfanhui 2020-10-20
liuhangtiant 2020-10-20