【发布时间】:2017-09-21 22:21:22
【问题描述】:
我对这行 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。声明的后半部分有些内容是错误的。
【问题讨论】:
-
在您的问题中添加操作系统(Ubuntu?)和 bash 版本。
-
如果您将该行复制粘贴到一个新脚本中,然后单独运行该脚本,您是否仍然会遇到同样的错误?
-
@thatotherguy 如果只是 if 语句,它就可以正常工作。但在完整的脚本中,它位于第 8 行,bash 告诉我“第 8 行:[: command not found”
-
@d1str0 您能否包含运行脚本的完整、未缩写的输出,包括您用来运行它的命令?它有
set -x,所以它应该打印大量有用的输出 -
@thatotherguy 更新