为什么 autoconf 脚本中的条件在变量前加上“x"? [英] Why do conditionals in autoconf scripts prefix variables with "x"?

查看:19
本文介绍了为什么 autoconf 脚本中的条件在变量前加上“x"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Why do conditional statements in autoconf scripts prefix their variables with "x"? For example, the macro provided by GNU to test for Boost has conditionals such as

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

为什么不定义为:

if test "$want_boost" = "yes"; then

推荐答案

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

In some early shells, testing for an empty string variable wasn't as easy as it is now, so the best alternative was to see if "x$variable" was equal to just "x". Also, since that's apparently using test, that's simpler than trying to properly quote/escape sequences like '$x != "y"' without losing sanity and/or portability.

这篇关于为什么 autoconf 脚本中的条件在变量前加上“x"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆