Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show and execute

In this makefile

dirs = $(shell ls)
clean:
    $(foreach dir,$(dirs),echo $(dir);)

The output is

$ make clean
echo bin; echo install.sh; echo Makefile; echo README.md; echo utils;
bin
install.sh
Makefile
README.md
utils

Why does it first show the command, then execute it? How I can omit the first line?

like image 658
JuanPablo Avatar asked Jun 27 '11 20:06

JuanPablo


2 Answers

Prepend the command with the @ character. Example:

dirs = $(shell ls)
clean:
    @$(foreach dir,$(dirs),echo $(dir);)
like image 175
Flimzy Avatar answered Oct 07 '22 01:10

Flimzy


From the manual (5.2 Recipe Echoing, bold emphasis mine):

Normally make prints each line of the recipe before it is executed. We call this echoing because it gives the appearance that you are typing the lines yourself.

When a line starts with @, the echoing of that line is suppressed. The @ is discarded before the line is passed to the shell. [...]


Alternatively:

The -s or --silent flag to make prevents all echoing, as if all recipes started with @.

like image 41
Chnossos Avatar answered Oct 07 '22 01:10

Chnossos