您的位置:首页 > 运维架构 > Shell

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

2017-04-17 16:37 281 查看
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


[b]3.判断赋值变量[/b]

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: