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.
我在我的 bash 脚本中编写了以下命令: service service1 status | grep -q "good"
service service1 status | grep -q "good"
在这里,我正在尝试quiet命令的输出service service1 status
quiet
service service1 status
请建议如何做到这一点?
我已经尝试过,但如果失败service service1 status | grep -q "good" > /dev/null,它仍然会给出命令输出service service1 status
service service1 status | grep -q "good" > /dev/null
问题不在于grep -q- 它不会产生任何输出。我认为service命令正在写入标准错误。所以,你需要重定向它:
grep -q
service
service service1 status 2>&1 | grep -q "good"
除非这样做,grep否则不会看到输出,service因此它在逻辑上也不正确。
grep