I know that the @ prefix suppresses output from a shell command in Makefiles, and also that the - prefix will ignore errors from a shell command. Is there a way to combine the two, i.e. a prefix that suppresses output and ignores errors? I don’t think @- or -@ works.
I know that the @ prefix suppresses output from a shell command in Makefiles,
Share
Actually,
@-and-@both do work, but will print amake: [target] Error 1 (ignored)warning.Instead, you can use
or, since
:is shorthand fortruein shell,This often a better thing to do, because it avoid Make’s confusing warning that an error was ignored in an invisible command.
Consider the two most common cases where you might want to ignore the return value of a command:
For the second case, consider the example of grepping for warnings in the log file produced by a command.
grepwill return an error if it does not find a match, which is not what you want:produces:
Using
@-produces a nonsensical ignored error warning when there is success, while|| truehandles both warnings and the absence of warnings without complaint.Theoretically using
|| trueis slower than using@-, but this overhead is unlikely to be a bottleneck in well-designed and -maintained build systems. The vast majority of the time should be spent building, or checking timestamps when there is nothing to build, not in running the thousands of quick commands whose return values all get ignored that would be necessary for this to have a measurable performance impact.