【问题标题】:autoconf shell script - What does "set x" (without "-") meanautoconf shell 脚本 - “set x”(不带“-”)是什么意思
【发布时间】:2014-05-07 21:39:23
【问题描述】:

在尝试更好地了解 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" "$@"

"set x" 似乎根本没有做任何事情,并且无论是否定义 x 都返回 0。

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

我错过了什么?

注意:不确定是否会有所不同,但在脚本前面已打开 posix 模式(set -o posix)

【问题讨论】:

    标签: set sh autoconf


    【解决方案1】:

    这是一个你不想潜水的兔子洞!如果$autom4te_options 是空字符串,那么eval set "$autom4te_options" 的行为就像set 没有参数并打印一堆垃圾。为了防止这种情况,使用set x $autom4te_options 代替,它总是将第一个位置参数($1)设置为“x”。然后移位重置所有位置参数。第 174-178 行可能正在测试死壳中的一个模糊错误(大多数自动工具的奇怪之处都可以做到这一点),其中一些壳调用了函数但未能正确保存位置参数。

    【讨论】:

    • 很好的答案。我也不知道“set ...”实际上设置了位置参数“$1 $2...”
    猜你喜欢
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-06
    • 2017-06-22
    • 2013-04-08
    • 2010-12-25
    • 1970-01-01
    相关资源
    最近更新 更多