What is wrong with this code?

Apr 13, 2010
318
7
62
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.
 
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.
 
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?
 
You should use an IFF statement.
Code:
IFF %everything.==okay. Then
  Echo Perfect
Else
  FixDisaster
Endiff
 

Similar threads