Suppress echo of command invocation in makefile?

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?


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).


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


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.


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 "..."