shell判断输入变量或者参数是否为空
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
判斷變量
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
判斷輸入?yún)?shù)
#!/bin/bash
if [ ! -n "$1" ] ;then
????echo "you have not input a word!"
else
????echo "the word you input is $1"
fi
以下未驗(yàn)證,轉(zhuǎn)自http://blog.csdn.net/lllxy/article/details/3255554
2. 直接通過變量判斷
???????如下所示:得到的結(jié)果為: IS NULL
#!/bin/sh
para1=
if?
[?
!?
$para1?
];?
then
?
?
echo?
"IS?NULL"
else
?
?
echo?
"NOT?NULL"
fi?
3. 使用test判斷
?????得到的結(jié)果就是: dmin is not set!??
#!/bin/sh
dmin=
if?
test?
-z?
"$dmin"
then
?
?
echo?
"dmin?is?not?set!"
else?
?
?
?
echo?
"dmin?is?set?!"
fi
?
4. 使用""判斷
#!/bin/sh?
dmin=
if?
[?
"$dmin"?
=?
""?
]
then
?
?
echo?
"dmin?is?not?set!"
else?
?
?
?
echo?
"dmin?is?set?!"
fi
轉(zhuǎn)載于:https://my.oschina.net/ghm7753/blog/507753
總結(jié)
以上是生活随笔為你收集整理的shell判断输入变量或者参数是否为空的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Codeforces Round #32
- 下一篇: 基于多进程和基于多线程服务器的优缺点及n