gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 14:32:02 27 4
gpt4 key购买 nike

为什么 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com