Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试运行[ pgrep mongo | wc -l -gt 2]以查看是否有超过 2 个 mongo 进程正在运行,但我不断收到此错误 -bash: [: missing `]'
[ pgrep mongo | wc -l -gt 2]
我觉得我在这里错过了一些简单的东西。谢谢!
您需要命令替换和之前的空格]:
]
[ $(pgrep mongo | wc -l) -gt 2 ]
$(...)是命令替换的语法
$(...)
除了使用命令替换,在这种情况下使用算术表达式是一个好主意:
(( $(pgrep mongo | wc -l) > 2 ))