英文:
surpress output of single line, multi command Makefile recipe
问题
我想抑制Makefile中某些命令的输出
例如,我有一个目标,stagel
stagel:
cd scripts && npm list body-parser || npm install body-parser
node scripts/app.js
我想抑制目标中第一行的输出。
我尝试过 @cd scripts && npm list body-parser || npm install body-parser
,但仍然会得到输出。我还尝试了在每个npm命令后添加@
,但得到了@npm: command not found
。
英文:
I would like to surpress the output of certain commands in my Makefile
For instance I have a target, stagel
stagel:
cd scripts && npm list body-parser || npm install body-parser
node scripts/app.js
I'd like to surpress the output of first line in the target.
I tried, @cd scripts && npm list body-parser || npm install body-parser
, but I still got the output. I also tried appending @
to each npm command, but got, @npm: command not found
答案1
得分: 1
我认为这个命令是不正确的:
cd scripts && npm list body-parser || npm install body-parser
这句话的意思是:“运行cd scripts
:如果cd
成功,运行npm list body-parser
,如果cd
失败,运行npm install body-parser
”。我不确定您确切想做什么,但我怀疑您想表达的是:“首先cd scripts
,然后运行npm list body-parser
,如果失败则运行npm install body-parser
”。要实现这一点,您需要类似这样的写法:
cd scripts && { npm list body-parser || npm install body-parser; }
关于“抑制第一行的输出”的含义并不清楚。您是指不希望make
打印出它正在运行的命令行吗?还是指不想显示命令的输出?
如果是前者,您的尝试@cd ...
将会达到这个效果。因为您对此不满意,我只能假设您指的是后者。
Make无法控制您运行的命令所生成的输出。如果您想抑制该输出,您需要自己使用正常的shell重定向操作来实现。例如:
stagel:
cd scripts && { npm list body-parser || npm install body-parser; } >/dev/null
node scripts/app.js
英文:
I think this command is not right:
cd scripts && npm list body-parser || npm install body-parser
This says, "run cd scripts
: if the cd
works, run npm list body-parser
and if the cd
fails, run npm install body-parser
". I don't know what you're trying to do for sure but I suspect what you want to say is, "first cd scripts
, then run npm list body-parser
and if that fails run npm install body-parser
". To do that you'll need something like this:
cd scripts && { npm list body-parser || npm install body-parser; }
It's not clear what you mean by "supporess the output of first line". Do you mean, you don't want make
to print out the command line it is running? Or do you mean, you don't want the output from the command to be shown?
If the former then your attempt @cd ...
will do that. Since you weren't happy with that I can only assume you mean the latter.
Make does not have anything to say about the output that commands you run generate. If you want to suppress that output you have to do it yourself, using normal shell redirection operations. For example:
stagel:
cd scripts && { npm list body-parser || npm install body-parser; } >/dev/null
node scripts/app.js
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论