whenever you do mycmd | grep mytext the return code of command got lost, $? point to the return code of grep. Back in time I posted https://laurentschneider.com/wordpress/2009/05/return-code-before-grep.html ( ( ( mycmd echo $? >&3 ) |grep mytext >&4 ) 3>&1 |(read x;exit $x) )4>&1 this did work like a charm for decades. But earlier […]