在尝试更好地了解 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))
最佳答案
这是一个你不想潜入的兔子洞!如果 $autom4te_options 是空字符串,则 eval set "$autom4te_options"的行为类似于不带参数的 set 并打印一堆垃圾。为了防止出现这种情况,可以使用 set x $autom4te_options
来代替,它始终将第一个位置参数 ($1) 设置为“x”。然后,移位会重置所有位置参数。第 174-178 行可能正在死 shell 中测试一个不起眼的错误(大多数自动工具的奇怪之处都是为了做到这一点),其中某些 shell 调用了函数,但未能正确保存位置参数。
关于set - autoconf shell 脚本 - "set x"(不带 "-")是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23510299/