在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"。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:shell怎么判断字符串是否为空