阅读量:62
在Linux中,可以使用以下命令来判断一个字符串是否为空:
if [ -z "$str" ]; then
echo "String is empty"
else
echo "String is not empty"
fi
其中,-z选项用于判断字符串是否为空,如果字符串为空,则返回true,否则返回false。在上面的示例中,如果变量str为空,则会输出"String is empty",否则输出"String is not empty"。