> $0 refers to the first argument. Where is the end? Is $9 the last
> accessible argument or $10...? Then using that reference must be followed by
> a split character.
> ant -- one two .... eleven
> <echo>$10HelloWorld</echo>
> a) two0HelloWorld
> b) elevenHelloWorld
Did you apply the patch? AFAIK, only ${NAME} expand references in ANT,
so <echo>$10HelloWorld</echo> should output exactly that, $10HelloWorld.
You'd need to write ${$10}HelloWorld if your intent is to re-reference the var.
> Printing out multiple arguments with $* seems to ignore $0.
> C:\oss\org_apache\ant16>build start -- toto titi tutu
> $* = titi tutu
> Where is "toto"?
> (not tested, just the docu in the bug-report)
toto is in $0.
The rational is to be able to have a generic 'start' or 'run' target,
which takes
not only arguments, but also a program name. Here's my canonical use case:
<!-- ====================================================
Runs arbitrary Java class (demo, example, benchmark)
-->
<target name="start" depends="init"
description="Runs arbitrary Java class (demo, example, benchmark)">
<fail unless="$0">Usage: build start -- <javaclass> [args]</fail>
<java classname="${$0}" fork="yes"> ...
<arg line="${$*}" />
</java>
</target>
Since Ant lacks functionality to manipulate sequences (like a .sh
shift, or XSL sequence processing using XPath functions), having the
"first" argument into a special $0 property enables this use, and
people who want all the arguments can simlpy do ${$0} ${$*}.
Put simply, it's to be able to use Ant as a mini program launcher.
> The sign: $
> Because it is a property the $ seems to be ok to me. Using with out
> the curly brackets {} shows the special meaning and avoids conflicts
> with existing properties. $1 != ${1}
Like I said, I didn't know Ant supported not using the curly braces...
> The number of arguments: $#
> Ok with me. ... ok, I often write perl ...
I don't use it, but thought I'd add it for completeness, and to be
consistent with other languages that also set it.
> The array: $*
> Should be a list which can easily be iterated by <ac:for>.
> I would prefer a comma separated list
> - easier for <ac:for> as the comma is its default separator
> - usually you (ok me) show a list separated by comma
All the special properties set, whose name start with $, are just
that, properties, i.e. plain strings. $* is designed to be use in <arg
line="${$*}" /> as the use case above shows, so it cannot be comma
separated.
I'm not too sure whether use with <ac:for> makes sense. I guess I
could also create a java.util.List<String> of all the arguments, and
put that in a reference called $*, then adding support for <ac:for>,
but I don't see a use for it personally.
> The dividing argument: --
> The '-' is a valid sign for target names, so '--' would be a valid target.
> But because a starting '-' is responsible for passing arguments to Ant,
> targets
> with a leading '-' cant be started from commandline. Which is there since
> .... a long time.
> And we dont have a '--' argument yet.
> Ok with me.
The -- "marker" argument is something usual in many Unix commands.
Usually means that the command should look no further for its
arguments, but the way I defined it is more in line with a program on
Solaris/CDE I was using a few years ago, that was used to start the
X11 server. Args before the -- were args to the X11-launching program,
while everything after the -- were (additional) args for X11 itself.
It's similar here, where everything before the (optional) -- is an
argument to Ant itself, while after the -- its an argument to
something else (a command, usually a <java> or <exec> task, started by
a given target).
> Additional task: <cliargs/>
> As this thread showed, we need to pass the parameters directly to <java> task
> (or <exec>...).
> So converting the $* parameter list to couple of <arg/> tags should be easy.
> The easiest would be a
> <arg line="$*"/>
> but with additional information this would become difficult.
> <arg value="-opt $0"/>
> <arg value="-opt $1"/>
> ...
> So my idea is something like
> <java|exec>
> <cliargs format="-opt *"/>
> </java|exec>
> which will be same with an "ant -- one two" as
> <java|exec>
> <arg value="-opt one"/>
> <arg value="-opt two"/>
> </java|exec>
> Makes sence or too special?
I think the use case is already supported, by leveraging <arg
line="${$*}" /> and using simple strings.
Does it make more sense? --DD
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]