Suppress echo of command invocation in makefile?

LinuxUnixMakefilePosix

Linux Problem Overview


I wrote a program for an assignment which is supposed to print its output to stdout. The assignment spec requires the creation of a Makefile which when invoked as make run > outputFile should run the program and write the output to a file, which has a SHA1 fingerprint identical to the one given in the spec.

My problem is that my makefile:

...
run:
     java myprogram

also prints the command which runs my program (e.g. java myprogram) to the output file, so that my file includes this extra line causing the fingerprint to be wrong.

Is there any way to execute a command without the command invocation echoing to the command line?

Linux Solutions


Solution 1 - Linux

Add @ to the beginning of command to tell gmake not to print the command being executed. Like this:

run:
     @java myprogram

As Oli suggested, this is a feature of Make and not of Bash.

On the other hand, Bash will never echo commands being executed unless you tell it to do so explicitly (i.e. with -x option).

Solution 2 - Linux

Even simpler, use make -s (silent mode)!

Solution 3 - Linux

You can also use .SILENT

.SILENT: run
hi:
     echo "Hola!"
run:
     java myprogram

In this case, make hi will output command, but make run will not output.

Solution 4 - Linux

The effect of preceding the command with an @ can be extended to a section by extending the command using a trailing backslash on the line. If a .PHONY command is desired to suppress output one can begin the section with:

@printf "..."

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnooblerView Question on Stackoverflow
Solution 1 - Linuxuser405725View Answer on Stackoverflow
Solution 2 - Linuxuser3619296View Answer on Stackoverflow
Solution 3 - LinuxKien PhamView Answer on Stackoverflow
Solution 4 - LinuxWileyView Answer on Stackoverflow