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
原文地址:https://www.cnblogs.com/sea-stream/p/10085845.html