【发布时间】:2014-04-16 22:27:20
【问题描述】:
在我的 Ubuntu 系统上,/usr/bin/ssh-copy-id 在顶部包含一段奇怪的代码。似乎检查/bin/sh 是一个“健全的外壳”。如果不是,它会尝试使用ksh 重新运行脚本。如果失败,它会举手并显示错误消息。
它到底在检查什么?特别是,if false ^ printf 做了什么,为什么它只在旧 shell 中触发?古代的 shell 曾经有一个 XOR 运算符,还是什么?
#!/bin/sh
# ...
# check that we have something mildly sane as our shell, or try to find something better
if false ^ printf "%s: WARNING: ancient shell, hunting for a more modern one... " "$0"
then
SANE_SH=${SANE_SH:-/usr/bin/ksh}
if printf 'true ^ false\n' | "$SANE_SH"
then
printf "'%s' seems viable.\n" "$SANE_SH"
exec "$SANE_SH" "$0" "$@"
else
cat <<-EOF
oh dear.
If you have a more recent shell available, that supports \$(...) etc.
please try setting the environment variable SANE_SH to the path of that
shell, and then retry running this script. If that works, please report
a bug describing your setup, and the shell you used to make it work.
EOF
printf "%s: ERROR: Less dimwitted shell required.\n" "$0"
exit 1
fi
fi
【问题讨论】:
-
顺便说一句,我认为@triplee 的编辑提供了价值。就其本身而言,标题看起来像是用户对 shell 的非技术性评论,而不是正在询问的错误消息。