如何判断是否正在从交互式外壳程序运行makefile? [英] How can I tell if a makefile is being run from an interactive shell?
问题描述
我有一个makefile,它运行可能需要一段时间的命令.如果构建是从交互式Shell启动的,那么我希望这些命令能使您变得轻松,而如果不是(特别是cron),则可以使这些命令更安静.(伪代码)的内容:
I have a makefile which runs commands that can take a while. I'd like those commands to be chatty if the build is initiated from an interactive shell but quieter if not (specifically, by cron). Something along the lines of (pseudocode):
foo_opts = -a -b -c
if (make was invoked from an interactive shell):
foo_opts += --verbose
all: bar baz
foo $(foo_opts)
这是GNU品牌.如果我正在做的事情很重要,我可以编辑问题.
This is GNU make. If the specifics of what I'm doing matter, I can edit the question.
推荐答案
并不是严格确定是否从交互式外壳程序中调用它,但是对于将输出重定向到文件的cron作业,该问题的答案与如何检测是否我的Shell脚本正在通过管道运行?:
It isn't strictly determining whether it is invoked from an interactive shell or not, but for a cron job in which the output is redirected to a file, the answer to this question would be the same as for How to detect if my shell script is running through a pipe?:
if [ -t 0 ]
then
# input is from a terminal
fi
编辑:要使用它在Makefile中设置变量(在GNU make中,就是这样):
To use this to set a variable in a Makefile (in GNU make, that is):
INTERACTIVE:=$(shell [ -t 0 ] && echo 1)
ifdef INTERACTIVE
# is a terminal
else
# cron job
endif
这篇关于如何判断是否正在从交互式外壳程序运行makefile?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!