Shell脚本判断内容为None的方式

1.判断变量

read -p "input a word :" word
 if  [ ! -n "$word" ] ;then
     echo "you have not input a word!"
 else
     echo "the word you input is $word"
 fi

2.判断输入参数

#!/bin/bash
 if [ ! -n "$1" ] ;then
     echo "you have not input a word!"
 else
     echo "the word you input is $1"
 fi

3.判断赋值变量

复制代码
TMOUT=`cat /etc/profile | grep TMOUT | awk -F[=] '{print $2}'`
echo $TMOUT

if [ ! $TMOUT ];then # 如果TMOUT为none
        echo "[ X ] 账号超时不存在自动注销,不符合要求,建议设置小于600秒" >> out.txt
else
        if [ $TMOUT -le 600 -a $TMOUT -ge 10 ] ; then
                echo "[ √ ] 账号超时时间${TMOUT}秒,符合要求" >> out.txt
        else
                echo "[ X ] 账号超时时间$TMOUT秒,不符合要求,建议设置小于600秒" >> out.txt
复制代码

 

from

posted @   北海悟空  阅读(2476)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示