寻找正确的语法,查看bash变量并确定它是否为null,如果是,则执行...否则继续.
也许是这样的 if [ $lastUpdated = null?; then... else...
tro*_*foe 12
只测试变量是否为空:
if [ -z "$lastUpdated" ]; then
# not set
fi
Run Code Online (Sandbox Code Playgroud)
扩展@chepner的评论,以下是如何测试未设置(而不是设置为可能为空的值)变量:
if [ -z "${lastUpdated+set}" ]; then
Run Code Online (Sandbox Code Playgroud)
如果未设置,则语法${variable+word}给出一个空字符串$variable;如果设置,则给出字符串“word”:
$ fullvar=somestring
$ emptyvar=
$ echo "<${fullvar+set}>"
<set>
$ echo "<${emptyvar+set}>"
<set>
$ echo "<${unsetvar+set}>"
<>
Run Code Online (Sandbox Code Playgroud)