- Jun
- 1,092
- 48
There are crucial differences between %$ and %*. In a batch script, the former treats commas as argument separators and %$ then produces a list of the arguments with a single space separating them (no matter how many spaces separated them in the command line). This is not what the help says. The help has the following:
It is not the command tail; it is a list of the arguments in the command tail. Thus, my script that simply echoes %$ produces the following:
If I change %$ to %* in test.btm, the result is quite different. Now I get the actual command tail.
To make matters more confusing, the behavior is not the same with alias parameters. The parameter %* returns a null value (not an error), and the parameter %$ returns what %* does for batch files.
I discovered this when trying to pass arguments to a script that uses @EVAL to do a calculation. If a numerical argument has a comma, it turns into two separate numbers when %$ is used. For a batch file, one has to use %*; for an alias, one has to use %$.
I did just notice that @EVAL now strips commas embedded in numbers (it didn't always do that, did it?), but it does not strip dollar signs. I'm often pasting text from a source that includes both, so I use either a script or alias. The help does say
It's not clear to me what is meant by "supporting commas". As far as I can tell, they are simply ignored (which is what I would want). Perhaps the same could be done for dollar sign characters (not parts of parameters). For now, I am stripping them myself (both commas and dollar signs) in the script or alias.
the complete command tail, modified by SHIFT
It is not the command tail; it is a list of the arguments in the command tail. Thus, my script that simply echoes %$ produces the following:
Code:
[TCC36.51.77 (19284) C:\temp]
->test.btm $4,0 * 2
arg: "$4 0 * 2"
If I change %$ to %* in test.btm, the result is quite different. Now I get the actual command tail.
Code:
[TCC36.51.77 (19284) C:\temp]
->test.btm $4,0 * 2
arg: "$4,0 * 2"
To make matters more confusing, the behavior is not the same with alias parameters. The parameter %* returns a null value (not an error), and the parameter %$ returns what %* does for batch files.
Code:
[TCC36.51.77 (19284) C:\temp]
->al test
set arg=%$ & echo arg: "%arg"
[TCC36.51.77 (19284) C:\temp]
->test $4,0 * 2
arg: "$4,0 * 2"
[TCC36.51.77 (19284) C:\temp]
->alias test & test $4,0 * 2
set arg=%* & echo arg: "%arg"
arg: "" $4,0 * 2
I discovered this when trying to pass arguments to a script that uses @EVAL to do a calculation. If a numerical argument has a comma, it turns into two separate numbers when %$ is used. For a batch file, one has to use %*; for an alias, one has to use %$.
I did just notice that @EVAL now strips commas embedded in numbers (it didn't always do that, did it?), but it does not strip dollar signs. I'm often pasting text from a source that includes both, so I use either a script or alias. The help does say
@EVAL also supports parentheses (to control evaluation order), commas, hexadecimals and decimal separators.
It's not clear to me what is meant by "supporting commas". As far as I can tell, they are simply ignored (which is what I would want). Perhaps the same could be done for dollar sign characters (not parts of parameters). For now, I am stripping them myself (both commas and dollar signs) in the script or alias.