如何从指挥线向马克茨提出论据?
I understand I can do
$ make action VAR="value"
$ value
www.un.org/spanish/ecosoc
VAR = "default"
action:
@echo $(VAR)
我如何得到以下行为?
$ make action value
value
如何
$make action value1 value2
value1 value2
如何从指挥线向马克茨提出论据?
I understand I can do
$ make action VAR="value"
$ value
www.un.org/spanish/ecosoc
VAR = "default"
action:
@echo $(VAR)
我如何得到以下行为?
$ make action value
value
如何
$make action value1 value2
value1 value2
你也许不这样做;你重开如何发挥作用的基本模式。 但这里的是:
action:
@echo action $(filter-out $@,$(MAKECMDGOALS))
%: # thanks to chakrit
@: # thanks to William Pursell
EDIT:
To explain the first command,
$(MAKECMDGOALS)
is the list of “targets” specified on the control line, e.g. “action Value1 Value2”.
<代码>filter-out是一种功能,从名单中删除一些内容。 ∗∗∗∗∗∗∗∗∗∗ (它可能更微妙,但在此我们不需要微妙。)
这些数字加在一起,$ (filter-out$@,$ (MAKECMDGOALS)
回到除“action”外的指挥线上列明的目标清单,该清单可能“价值1” 。
Here is a generic working solution based on @Beta s
I m using GNUMak 4.1 with SHELL=/bin/bash
atop myMakfile, so YMMV!
This allows us to accept extra arguments (by doing nothing when we get a job that doesn t match, rather than throwing an error).
%:
@:
这是一项给我们带来动力的宏观:
args = `arg="$(filter-out $@,$(MAKECMDGOALS))" && echo $${arg:-${1}}`
Here is a job which might call this one:
test:
@echo $(call args,defaultstring)
结果是:
$ make test
defaultstring
$ make test hi
hi
Note! You might be better off using a "Taskfile", which is a bash pattern that works similarly to make, only without the nuances of Maketools. See https://github.com/adriancooney/Taskfile
更为容易。 考虑一项任务:
provision:
ansible-playbook -vvvv
-i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
--private-key=.vagrant/machines/default/virtualbox/private_key
--start-at-task="$(AT)"
-u vagrant playbook.yml
我现在要说的话,我只是说:
<条码>AT=“造型资产”
或者说:
<编码>make provision in this case AT
is an food string
几年后,希望就此建议<代码>just:。
action v1 v2=default:
@echo take action on {{v1}} and {{v2}}...
You will be better of defining variables and calling your make instead of using parameters:
文件
action: ## My action helper
@echo $$VAR_NAME
终端站
> VAR_NAME="Hello World" make action
Hello World
不要试图这样做
$ make action value1 value2
而是用文字:
#! /bin/sh
# rebuild if necessary
make
# do action with arguments
action "$@"
并且:
$ ./buildthenaction.sh value1 value2
更多解释为什么做这种解释,以及用纸质黑板对另一个非常相似但似乎不重复的问题:。
I m trying to add my file in Visual Studio as command line parameters. I know my code works since when I use fopen("whole path here", "r"), it runs. I then add the file as a command line parameter ...
I ve written a command line utility that uses getopt for parsing arguments given on the command line. I would also like to have a filename be an optional argument, such as it is in other utilities ...
I m generating a large XML document via a Perl script in a command window, however, currently it s printing the document to standard out. The Perl script modifiers do not have a switch to allow to ...
I am trying to retrieve the environment variable to detect whether the system is 32 or 64 bit. But on 64 bit server the environment variable %processor_architecture% is returning x86 instead of AMD64. ...
I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...
This code will read a line from a text file: set file = CreateObject("Scripting.FileSystemObject").OpenTextFile("c: umber.txt", 1) text = file.ReadLine MsgBox text How can I make it read repeatedly ...
I have a batch script that takes arguments from the command line. One of the arguments has a * in it. In spite of putting the argument in quotes, the * gets expanded before the argument gets used in ...
How can I create an empty file at the DOS/Windows command-line? I tried: copy nul > file.txt But it always displays that a file was copied. Is there another method in the standard cmd? It should ...