Linux 抑制 makefile 中命令调用的回显?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9967105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Suppress echo of command invocation in makefile?
提问by noobler
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.
我为一项作业编写了一个程序,该程序应该将其输出打印到标准输出。分配规范需要创建一个 Makefile,当调用它时make run > outputFile
应该运行程序并将输出写入一个文件,该文件的 SHA1 指纹与规范中给出的指纹相同。
My problem is that my makefile:
我的问题是我的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.
还将运行我的程序的命令(例如 java myprogram)打印到输出文件,以便我的文件包含导致指纹错误的额外行。
Is there any way to execute a command without the command invocation echoing to the command line?
有没有办法在没有命令调用回显到命令行的情况下执行命令?
采纳答案by noobler
Add @
to the beginning of command to tell gmake not to print the command being executed. Like this:
添加@
到命令的开头告诉 gmake 不要打印正在执行的命令。像这样:
run:
@java myprogram
As Oli suggested, this is a feature of Make and not of Bash.
正如 Oli 所建议的,这是 Make 的一个特性,而不是 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).
另一方面,Bash 永远不会回显正在执行的命令,除非您明确告诉它这样做(即使用-x
选项)。
回答by Wiley
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:
@
通过在行上使用尾随反斜杠扩展命令,可以将命令前面带有 的效果扩展到一个部分。如果需要一个.PHONY
命令来抑制输出,可以用以下内容开始本节:
@printf "..."
回答by user3619296
Even simpler, use make -s
(silent mode)!
更简单,使用make -s
(静默模式)!