我想将一个字符串grep到adb logcat,如果它匹配,它应该进入if if else else exit.THe以下代码不起作用
if[ ./adb logcat | grep --line-buffered 'Monkey aborted due to error.' ]; then
adb logcat -d > MONKEY_WORKING_DIR/logcat_MonkeyWithoutPackageName.txt
fi
答案 0 :(得分:3)
如果要测试表达式的值,则只使用[
,而不是要测试命令是否成功。如果您正在测试命令行,只需将该命令放在if
之后。
if ./adb logcat | grep --line-buffered 'Monkey aborted due to error.'
then
...
fi
此外,您需要在if
和[
之间留出空格。