WAD Premature expansion of ~n

Aug 23, 2010
688
9
Code:
ALIAS TAXX=@ECHO -f ^"^%~1^" -- ^%2$
ALIAS TAXX
CALL :TEST

ALIAS TAXX=@ECHO -f "%%@UNQUOTES[%%1]" -- ^%2$
ALIAS TAXX
CALL :TEST

GOTO :EOF

:TEST
TAXX 1 2 3 -- 5
CALL :SUB 5
GOTO :EOF

:SUB
TAXX 1 2 3 -- %$
GOTO :EOF
 
Aug 23, 2010
688
9
Sample output, sorry…
Code:
@ECHO -f "%~1" -- %2$
-f "" -- 2 3 -- 5
-f "5" -- 2 3 -- 5
@ECHO -f "%@UNQUOTES[%1]" -- %2$
-f "1" -- 2 3 -- 5
-f "1" -- 2 3 -- 5
 
May 20, 2008
12,165
133
Syracuse, NY, USA
What's "%~1" supposed to do? Where is it documented?

I found "%~1$" in the help, but that asks for all the parameters 1 to 0!
 

rconn

Administrator
Staff member
May 14, 2008
12,556
167
I'm unclear why you're using a CMD kludge for a batch file that won't run in CMD, but ...

You're confusing alias arguments with batch variables. They are not the same, and TCC does not support the (bizarre) CMD ~ batch / environment variable syntax when expanding aliases.
 
Aug 23, 2010
688
9
Bizzare it may be, but concise and easy to write.
And of all the things, the current behavior is most surprising.
 
Aug 23, 2010
688
9
At least a note that
[[/cmdsyntax.htm The CALL-mode parameter expansion]] is not supported in alias parameters and may lead to surprising results. Please use appropriare TC variable functions (@UNQUOTES, @FULL, @DRIVE, @PATH, @NAME, @EXT) instead.
at the top of "Alias Parameters" section of /alias.htm would be enough.
 

rconn

Administrator
Staff member
May 14, 2008
12,556
167
Technically, that syntax isn't part of CALL. CMD originally introducted it for FOR arguments, then added it to batch arguments (either starting a batch file directly or through CALL).

Aliases are not the best tool for what you're doing here -- aliases arguments are nothing like batch files arguments. You should be using library functions (or perhaps user-defined functions), which will allow you to use the extended batch argument processing.
 
Aug 23, 2010
688
9
I'm not near that boat yet, but I'll look int them once I solve more pressing issues.
Thanks for your support, working with 4NT (and TCC) through these years was a pleasure. Mostly.
 

Similar threads