What is wrong with this code?

Apr 13, 2010
310
7
61
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,466
88
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,503
16
Solon, OH, USA
You should use an IFF statement.
Code:
IFF %everything.==okay. Then
  Echo Perfect
Else
  FixDisaster
Endiff
 
Similar threads
Thread starter Title Forum Replies Date
M What am I doing wrong in this (very simple!) code? Support 3
JohnQSmith New online help file wrong logo Support 7
vefatica @EXECSTR ... TCSTART ... something's wrong! Support 7
R History window wrong size, can't remember size change Support 12
mfarah Fixed The DATE command produces the wrong error message. Support 1
MikeBaas @regsetenv complains "wrong parameter" Support 14
mikea How to? TCC registered to wrong 'entity' Support 5
T @replace -- what is wrong here Support 2
vefatica Fixed KEYSTACK /i with repeat count sends wrong keys Support 7
C ZIP/U compares wrong timestamp Support 13
vefatica @WORDS, often wrong Support 0
vefatica gcd() ... wrong answer, lcm() hangs Support 5
vefatica WAD DIR /HL still gets names wrong Support 16
H Fixed DIR /G returns wrong sizes Support 2
M Another "What is wrong?" Support 8
M What is wrong with this command? Support 4
vefatica Updater says wrong version Support 1
CWBillow Wrong icons keep sticking Support 6
M How to? What am I doing wrong/not understanding? Support 10
C News link wrong Support 1
M What am I doing wrong? Support 12
M What am I doing wrong here? Support 2
C Forum column headings wrong? Support 4
gschizas Installation folder for TCMD x64 15.1 is wrong Support 5
Dan Glynhampton Documentation v15 help: ECHOXERR Help Page Title is Wrong Support 0
vefatica Something wrong with @PID Support 10
J zip wrong central directory signature Support 12
S Fixed _DO_FILES and _DO_DIRS wrong Support 0
B Downloading Updates - Error: Wrong file size?? Support 3
vefatica What's wrong here? Support 2
vefatica Wrong startup file? Support 1
M How to? Missing closing quote: What am I doing wrong???? Support 7
gschizas (minor) Help topic "Colors, Color Names and Codes" is wrong Support 0
T Wrong prompt in Windows command console Support 3
M Where am I going wrong with ALIAS??? Support 7
G Wrong File Size Support 8
vefatica Updating v10: error wrong file size Support 2
S Wrong .INI file used by TCC Support 2
K_Meinhard Wrong sender adress Support 0
M Goto fails when a text endtext block precedes the code Support 5
rconn News Update: Code Signing Certificate Status Support 16
Peter Murschall UNICODE mixed with ANSI Code Support 11
A Inconsistent return code for TCC scripts Support 4
D v20 code page behavior changes Support 2
vefatica Code page? Support 1
vefatica Exit code of a batch file? Support 4
rconn News Take Command code signing certificate Support 0
Phileosophos Documentation TPIPE /string type code confusion Support 4
M How to? Get the return code from an external program... Support 8
M Why does this code produce these results? Support 2

Similar threads