bash - 如何在 Bash 中查找变量是否为空

标签 bash shell is-empty

如何检查 Bash 中的变量是否为空?

最佳答案

在 Bash 中,至少以下命令测试$var 是否为空:

if [[ -z "$var" ]]; then
   # $var is empty, do what you want
fi

命令 man test 是你的 friend 。

关于bash - 如何在 Bash 中查找变量是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3061036/

相关文章:

mongodb - 我的数据库记录被删除(带 sails )

database - 检查表是否为空(MSAccess 数据库 + Delphi)

linux - Bash 脚本 - 如何设置创建新文件的组?

java - 如何检查所有 JTexFields 是否为空?

linux - 脚本不在 bg 中运行

c++ - 将 C++ CGI 脚本作为后台进程运行?

linux - 如何通过现有进程模拟高 CPU 峰值

linux - 如何将多个链接下载到一个文件中?

bash - git 别名可以像 bash 别名一样扩展吗?

linux - 使用 shell 脚本在电子邮件中附加一个 html 文件