Makefile is as follows :
THIS.txt : foo.txt
grep THIS foo.txt > $@
When grep output is empty (no THIS in foo.txt), make gives an error message, bash does not :
$ make
make:*** [THIS.txt] Error 1
$ grep THIS foo.txt > THIS.txt
$ grep THIS foo.txt 2>&1
How come? How should I modify my makefile to avoid an error message when grep output is empty?
grepdoesn’t give an error in bash, but it does return a non-zero exit code:If you want to get rid of that non-zero exit code, so that
makewon’t flag it as an error, you can do this:The
|| truebit says “if there is a nonzero exit code, return the exit code oftrueinstead (which is always0in bash).