Welcome!

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

SignUp Now!

What is wrong with this code?

Apr
318
7
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.
 
Both sides are expanded, no matter whether the condition is true or false.
 
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.
 
Here's your alias, turned inside-out:
Code:
alias test=`@echo %@full[%@if[%# eq 0,%_cwd,%1]]`
 
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

G
Replies
8
Views
3K
Back
Top