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

时间:2022-01-23 01:06:33

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 -a $TMOUT -ge ] ; then
echo "[ √ ] 账号超时时间${TMOUT}秒,符合要求" >> out.txt
else
echo "[ X ] 账号超时时间$TMOUT秒,不符合要求,建议设置小于600秒" >> out.txt

from