【发布时间】:2017-02-03 10:22:52
【问题描述】:
我正在尝试对 bash 脚本中两个 grep 命令的结果进行条件检查,但我似乎无法像这样将它们组合起来:
if [[ $( stout_cmd1 | grep -q 'check_txt1' ) || ( $( stdout_cmd2 | grep -q 'check_txt2' ) ]] ; then
//do something here if output of stdout_cmdX contains text check_txtX
fi
因为它总是返回 false。按预期有条件地检查自己工作的命令:
if stdout_cmd1 | grep -q 'check_txt1' ; then
或
if stdout_cmd2 | grep -q 'check_txt2' ; then
我不知道如何检查其中一个是否正确。如何在条件检查中组合两个标准输出输出?我已经从 grep 调用中删除了 -q 标志,但没有任何效果。
【问题讨论】:
-
试试这个:
if { stout_cmd1 | grep -q 'check_txt1' } || { stdout_cmd2 | grep -q 'check_txt2' }; then
标签: bash if-statement grep stdout