【发布时间】:2015-04-13 05:08:48
【问题描述】:
我正在尝试了解项目的 configure.ac 文件中的常见模式。我相当确定这是一个我很难解析的 bashism。这是一个例子:
LDFLAGS="${LDFLAGS:+$LDFLAGS }$OTHERFLAG"
其意图似乎是通过 OTHERFLAG 中的内容来扩展 LDFLAGS 的当前值。看起来写起来会更简单:
LDFLAGS="$LDFLAGS $OTHERFLAG"
相关section in the bash manual说:
${parameter:+word}
If parameter is null or unset, nothing is substituted, otherwise the expansion of word is substituted.
我认为这里有一些防御性的东西,但我不确定到底是什么。
【问题讨论】:
-
作为旁注,这不是 bashism; it's a standard parameter expansion, specified by POSIX.