autoconf - 为什么 autoconf 脚本中的条件用 "x"前缀变量?

标签 autoconf

为什么 autoconf 脚本中的条件语句在它们的变量前加上“x”?例如,GNU 提供的用于测试 Boost 的宏具有条件,例如

if test "x$want_boost" = "xyes"; then

为什么这不是定义为:
if test "$want_boost" = "yes"; then

最佳答案

在一些早期的 shell 中,测试空字符串变量不像现在那么容易,所以最好的替代方法是查看“x$variable”是否等于“x”。另外,因为这显然是在使用 test ,这比在不失去理智和/或可移植性的情况下尝试正确引用/转义序列(如 '$x != "y"' 更简单。

关于autoconf - 为什么 autoconf 脚本中的条件用 "x"前缀变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11265847/

相关文章:

c++ - 关于如何部署 C++ 代码以在任何地方工作的提示

autoconf - 在哪里放置 GNU autoconf/automake 的帮助脚本?

python - 如何在Python中自动安装缺少的模块?

php - 默认的 PHP 配置是什么?

C 未定义对 `some_foo' 的引用

autoconf 和 automake 对比 -O2 对比 -O3

c++ - lib 和带有 autoconf 的模块有什么区别

mingw - 如何使用 MinGW/MSYS 升级到 autoconf 2.69

Autotools:top_srcdir 和 abs_top_srcdir 为空

compilation - docker 无法编译程序(可能是未定义的宏AC_MSG_ERROR)