问题描述
在 bash 脚本 $eval ${cmds[1]}
上执行此命令后,它有输出:
about to fork child process//
forked process: 1234
all output going to: /rand/direc/filename.log
child process started successfully,parent exiting.
我想在 bash 中编写一个条件,在其中查找“子进程已成功启动”,并执行某些命令,
else echo -e "child process not started successfully"
解决方法
Grep 字符串管道命令的执行到 tee /dev/tty 以将命令的输出显示到屏幕
if eval ${cmds[1]} | tee /dev/tty | grep -q "child process not started successfully"
then
echo "OK"
fi