shell条件语句

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

判断目录是否存在

 

posted @ 2019-05-26 19:07  FAJ  阅读(213)  评论(0编辑  收藏  举报