码迷,mamicode.com
首页 > 系统相关 > 详细

shell条件语句

时间:2019-05-26 19:48:58      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:style   col   存在   判断目录   this   color   The   class   roo   

if (表达式);

语句1

elif

语句2

else

fi

 

if(())用户判断大小

#!/bin/bash
#auto if test

NUM=100

NUM1=200

if (($NUM>$NUM1));then
        echo "this $NUM greate $NUM1 "
else
        echo   "this  $NUM  XIAOU $NUM1

 

逻辑运算符解析:
-f  判断文件是否存在

-d判断目录是否存在

-gt 大于

-z 空字符串

root@yisheng-v-m:/home/yisheng/shell# /bin/bash -n 5.sh
root@yisheng-v-m:/home/yisheng/shell# 

-n用于测试代码是否正确,无输出为正确

 

#!/bin/bash
#by hou 2019

DIR=/tmp/2019

if [ ! -d $DIR ];then
        mkdir -p $DIR
        echo -e "\033[32mthis $DIR create success!\033[0m"
else
        echo -e "\033[32mthis $DIR exit!\033[0m"
fi

判断目录是否存在

 

shell条件语句

标签:style   col   存在   判断目录   this   color   The   class   roo   

原文地址:https://www.cnblogs.com/fbjtcp/p/10927090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!