我有这个脚本:
#!/usr/bin/env sh
# note: we must use sh instead of bash, it's more cross-platform
set -e;
if [[ "$skip_postinstall" == "yes" ]]; then # TODO rename 'skip_postinstall' to something more specific
echo "skipping postinstall routine.";
exit 0;
fi
export FORCE_COLOR=1;
export skip_postinstall="yes"; # TODO rename 'skip_postinstall' to something more specific
mkdir -p "$HOME/.oresoftware/bin" || {
echo "Could not create .oresoftware dir in user home.";
exit 1;
}
(
echo 'Installing run-tsc-if on your system.';
curl -H 'Cache-Control: no-cache' -s -S -o- 'https://raw.githubusercontent.com/oresoftware/run-tsc-if/master/install.sh' | bash || {
echo 'Could not install run-tsc-if on your system. That is a problem.';
exit 1;
}
) 2> /dev/null
if [[ "$(uname -s)" != "Darwin" ]]; then
exit 0;
fi
if [[ ! -f "$HOME/.oresoftware/bin/realpath" ]]; then
(
curl --silent -o- 'https://raw.githubusercontent.com/oresoftware/realpath/master/assets/install.sh' | bash || {
echo "Could not install realpath on your system.";
exit 1;
}
)
fi
# the end of the postinstall script
当我运行它时,我得到:
./assets/postinstall.sh: 7: ./assets/postinstall.sh: [[: not found
Installing run-tsc-if on your system.
=> Installing 'run-tsc-if' on your system.
=> run-tsc-if download/installation succeeded.
./assets/postinstall.sh: 29: ./assets/postinstall.sh: [[: not found
./assets/postinstall.sh: 33: ./assets/postinstall.sh: [[: not found
但是如果我用单括号替换双 [[ 括号,我得到:
./postinstall.sh: 7: [: unexpected operator
这只是来自:
if [ "$skip_postinstall" == "yes" ]; then
echo "skipping postinstall routine.";
exit 0;
fi
嗯,我该怎么办?我尝试使用test
而不是[
并且[[
这也不起作用。
[[
是源自 ksh 的“扩展测试”,也受 bash/zsh 支持,因此它不应该识别它们。此外,该==
运算符不是 POSIX,=
是用于字符串比较的 shell 测试运算符。这是两个非常常见的bashisms。
我认为这是因为 sh 无法处理 == 比较,所以它需要:
不是这个
蹩脚的