Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

DO i=1 to %# in an alias?

May
13,834
211
Why doesn't this work?

Code:
v:\> alias nargs `do i=1 to %# ( echo %[%i] )`

v:\> nargs a b c
Usage : DO [n | FOREVER]

According to the help for ALIAS,

The special parameter %# contains the number of command line parameters.
 
Code:
R:\>alias test=`echo %#`

R:\>test
0

R:\>test 1 2 3
3 1 2 3

Why is this happening in the alias?

From a .btm file;
Code:
echo %#

Output;
Code:
R:\>test.btm
echo 0
0

R:\>test.btm 1 2 3
echo 3
3

Correct results from a .btm

Joe
 
Code:
R:\>alias nargs `set argv=%# & echo %argv`

R:\>nargs
0

R:\>nargs 1 2 3
3 1 2 3

Works correctly from a .btm

Joe
 
Code:
Code:
R:\>alias test=`echo %#`

R:\>test
0

R:\>test 1 2 3
3 1 2 3

Aha! %$ is being appended because the parameters are not explicitly used.

If the same were done in my example, it'd turn into the likes of this and give the error message..

Code:
v:\> do i=1 to 3 (echo %i) 1 2 3
Usage : DO [n | FOREVER]
 
And my example is apparently doomed for another reason. It seems like %[1] gives an empty string in an alias (in a BTM, it's the same as %1).

Code:
v:\> alias nargs `echo **%1**`

v:\> nargs foo
**foo**

Code:
v:\> alias nargs `echo **%[1]**`

v:\> nargs foo
**** foo
 
Back
Top