我对这行 shell 脚本有疑问:
if [ "$(lsb_release -r -s)" == "16.04" ] || [ "$(lsb_release -r -s)" == "17.04" ]; then
运行脚本时出现“[: command not found”。我不懂为什么。
+ '[' -f /etc/debian_version ']'
++ lsb_release -r -s
+ '[' 17.04 == 16.04 ']'
++ lsb_release -r -s
+ ' [' 17.04 == 17.04 ']'
./mhn/scripts/install_mongo.sh: line 8: [: command not found
如果在 17.04 上运行,我只会收到错误,而不是 16.04。如果我切换语句并首先检查 17.04,它将在 16.04 中断,而不是 17.04。声明后半部分的某些内容正在打破。
https://github.com/ngatilio/mhn/blob/2e992934a350e0367a214dc86cc63e7ecd5d59ef/scripts/install_mongo.sh
最佳答案
你的问题是:
+ ' [' 17.04 == 17.04 ']'
在最后一个
[
之前,您似乎有某种时髦的空格字符。 .删除并重新键入它以将其变成常规的 ascii 空间。当您在此处复制粘贴该行时,或者通过非原始 github View 查看它时,它会被转换为常规空间,因此它不会出现在您的帖子中。这也是为什么它在复制粘贴到另一个文件时可以正常工作的原因。
这是从 github 下载(而不是复制粘贴)的文件的 ShellCheck:
$ shellcheck install_mongo.sh
In install_mongo.sh line 8:
if [ "$(lsb_release -r -s)" == "16.04" ] || [ "$(lsb_release -r -s)" == "17.04" ]; then
^-- SC1018: This is a unicode non-breaking space. Delete and retype it.
关于Bash if 或语句,找不到命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46354006/