Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress echo of command invocation in makefile?

People also ask

How do you silence a Makefile?

If you want to inhibit the display of commands during a particular make run, you can use the -s option. If you want to inhibit the display of all command lines in every run, add the special target . SILENT to your makefile . and there is no file named xyz , make halts after rm returns its exit status.

What is @echo in Makefile?

The ' @ ' is discarded before the line is passed to the shell. Typically you would use this for a command whose only effect is to print something, such as an echo command to indicate progress through the makefile: @echo About to make distribution files.

How does the make command work?

The make command uses information from a description file, which you create, to build a file containing the completed program, which is then called a target file. The internal rules for the make command are located in a file that looks like a description file.


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