Suppress echo of command invocation in makefile?

前端 未结 4 748
迷失自我
迷失自我 2021-01-30 06:13

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

相关标签:
4条回答
  • 2021-01-30 06:18

    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.

    0 讨论(0)
  • 2021-01-30 06:20

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

    0 讨论(0)
  • 2021-01-30 06:29

    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 "..."
    
    0 讨论(0)
  • 2021-01-30 06:33

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

    0 讨论(0)
提交回复
热议问题