$ python2 -m doesnt_exist |& grep -q 'No module named' && echo 'Nope' || echo 'Yup' Nope $ python2 -m math |& grep -q 'No module named' && echo 'Nope' || echo 'Yup' Yup