Welcome!

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

SignUp Now!

WAD DO Command Fails in Alias with a Parameter for Count or Condition

Jun
760
16
Shouldn't the alias shown below work?

alias zz & zz one two three
echo Parameter count = %# & do %# (echo test)
Parameter count = 3
Usage : DO [n | FOREVER]

It's not only the parameter %# that doesn't work with DO.

alias zz & zz one two three
set count=%# & echo Parameter count = %count & do %count (echo test)
Parameter count = 3
Usage : DO [n | FOREVER]

DO does accept parameters when run directly from the command line rather than an alias.

set count=3 & do %count (echo test)
test
test
test

It also works from a batch file.

type test.btm & test.btm one two three
echo Parameter count = %#
do %# (echo test)
Parameter count = 3
test
test
test

Am I misunderstanding something that explains why it does not work in an alias?
 
You can use REM to eat the unwanted args:

Code:
C:\>alias zz
echo Parameter count = %# & do %# ( echo test ) & rem

C:\>zz foo bar baz quux
Parameter count = 4
test
test
test
test

C:\>
 
Oh, so you are saying that the problem is caused by the parameters that are not referenced? I've gotten tripped up by that before. Apparently those are being appended after the closing parenthesis, and that creates an invalid DO command.

I'm going to have to go through my alias definitions to see if any of them would be adversely affected when the command line has more parameters than the alias expects and processes.
 
So, Rex, how can you make me remember that :smile: ?

Would it make sense to have a configuration option to turn off that feature? I think I prefer to be explicit about the parameters I want to use (and, as I wrote, have gotten tripped up a number of time by the appending of unreferenced arguments). I do realize that changing the default would break some aliases, but an option could be acceptable.
 
@rconn
Please do not make that as config option, that would be too "dangerous" for unexperienced users (for that purpose) to break some alias stuff.

@Jay Sage
It's really not necessary to have a such option IMHO. Read also my comment for Rex ...
"& rem" is your friend as @Charles Dye suggested.
 
So, Rex, how can you make me remember that :smile: ?

Would it make sense to have a configuration option to turn off that feature? I think I prefer to be explicit about the parameters I want to use (and, as I wrote, have gotten tripped up a number of time by the appending of unreferenced arguments). I do realize that changing the default would break some aliases, but an option could be acceptable.

If I made if a configuration option & you set it, you could be pretty much guaranteed that you would not be able to run third-party aliases and batch files. Which would generate another bug report ...
 
If I made if a configuration option & you set it, you could be pretty much guaranteed that you would not be able to run third-party aliases and batch files. Which would generate another bug report ...
In my case, probably not. I am not aware that I am using any third-party aliases or batch files. Even when I was at work, I used only my own code. But that's OK. I realize that you have a lot of people to support, and even if I didn't encounter a problem and complain, others would.

I generally encounter this when I am trying to test something, not when I am actually doing some real work. I'll just have to try to remember. Or, worst case, I'll make another false bug report and be corrected here :smile:
 
Back
Top