在我的Ubuntu系統上,/usr/bin/ssh-copy-id
包含一個好奇的一段代碼。它似乎檢查/bin/sh
是一個「理智的外殼」。如果不是,它會嘗試用ksh
重新運行該腳本。如果失敗了,它會拋出雙手並顯示錯誤消息。需要更少的昏暗的外殼
究竟是什麼檢查?特別是,if false^printf
是做什麼的,爲什麼它只能在舊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" "[email protected]"
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
順便說一句,我認爲@三合一編輯提供的價值。標題本身看起來像用戶對shell的技術評論比較少,而不是被詢問的錯誤消息。 –