autoconf shell脚本 - "设置x" (没有" - ")意思是

时间:2014-05-07 06:26:41

标签: set sh autoconf

在尝试更好地理解autoconf shell脚本(/ usr / bin / autoconf)如何工作时,我遇到了以下两行:

174 if ( set x; as_fn_ret_success y && test x = \"\$1\" ); then :
175 
176 else
177   exitcode=1; echo positional parameters were not saved.
178 fi

然后在同一个剧本中:

500 # Run autom4te with expansion.
501 eval set x "$autom4te_options" \
502   --language=autoconf --output=\"\$outfile\" "$traces" \"\$infile\"
503 shift
504 $verbose && $as_echo "$as_me: running $AUTOM4TE $*" >&2
505 exec "$AUTOM4TE" "$@"

"设置x"似乎根本不做任何事情,无论是否定义了x,都会返回0。

更令人困惑的是上面的501-502行似乎也没有做任何事情

我错过了什么?

注意:不确定它是否有所不同但是脚本模式在脚本前面打开(设置-o posix))

1 个答案:

答案 0 :(得分:4)

这是一个兔子洞,你不想潜水!如果$autom4te_options是空字符串,则eval set "$autom4te_options"的行为类似于set,没有参数,并打印出一堆副本。为了防止这种情况,使用set x $autom4te_options代替,它总是将第一个位置参数($ 1)设置为“x”。然后移位重置所有位置参数。第174-178行可能正在测试一个死壳中的一个模糊的bug(大多数自动工具存在奇怪的事情),其中一些shell调用了函数但未能正确保存位置参数。