Checking if output of a command contains a certain string in a shell script October 21, 2022 by Tarik Testing $? is an anti-pattern. if ./somecommand | grep -q 'string'; then echo "matched" fi