What is wrong with this code?

Apr 13, 2010
298
7
60
The Hague
Code:
alias test=@echo %%@if[%%# eq 0,%%@full[%%_cwd],%%@full[%%1]]
If no args, the second branch gets executed. Why?
I'm looking to provide cwd as a default if nothing is passed to the alias.

Regards, DJ.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,223
78
Albuquerque, NM
prospero.unm.edu
The same is true of any function. All the arguments inside the square brackets will be expanded, before the function itself is evaluated. @IF is no different; the parser doesn't handle it differently.
 
Aug 3, 2016
376
9
Netherlands
The same is true of any function. All the arguments inside the square brackets will be expanded, before the function itself is evaluated. @IF is no different; the parser doesn't handle it differently.
Thanks for the explanation! (I was not aware of this, although it is quite obvious (in hindsight :-) )

Does this mean that @IF is not suited for things like:
echo %@IF[_%everything%_ == _okay_, Perfect, %@exec[FixDisaster.exe]]
or is there some clever way to work around this?
 

samintz

Scott Mintz
May 20, 2008
1,424
13
Solon, OH, USA
You should use an IFF statement.
Code:
IFF %everything.==okay. Then
  Echo Perfect
Else
  FixDisaster
Endiff