shell 判断一个字符串是否为空

 

test.sh

#!/bin/bash
echo "enter the string:"
read filename
if test $filename ; then
echo "it's not zero"
else
echo "it's zero"
fi

执行

sudo chmod +x test.sh
./test.sh

输出

enter the string:

it's zero

 

执行

./test.sh

输出

enter the string:
kk
it's not zero

 

posted @ 2018-12-07 23:33  anobscureretreat  阅读(890)  评论(0编辑  收藏  举报