Bug in variable expansion

Aug 16, 2008
124
0
[Lates TCC (v67)]

[Cmd.exe]
> dir "%ProgramFiles(x86)%"
[...]
Directory of C:\Program Files (x86)

31-May-11 00:12 <DIR> .
[...]
1 File(s) 174 bytes
26 Dir(s) 112,201,871,360 bytes free

[TCC]
dir "%ProgramFiles(x86)"
TCC: (Sys) The system cannot find the file specified.
"C:\Program Files(x86)"
0 bytes in 0 files and 0 dirs
112,201,871,360 bytes free

Note that TCC has expanded %ProgramFiles(x86) to "C:\Program Files(x86)" (instead of "C:\Program Files (x86)" (with space between Files and (x86)".

But:
> set ProgramFiles(x86)
C:\Program Files (x86) (which is correct)
 

rconn

Administrator
Staff member
May 14, 2008
12,344
149
Note that TCC has expanded %ProgramFiles(x86) to "C:\Program Files(x86)" (instead of "C:\Program Files (x86)" (with space between Files and (x86)".

Not a bug. The ( and ) are not valid variable name characters, so the parser is expanding "%ProgramFiles" and then appending "(x86)" to the result.

If you want to use unusual characters in the filename, you can force the parser to recognize them with the [] syntax:

echo %[ProgramFiles(x86)]

Or you can use the CMDVariables=Yes option in your TCMD.INI, which will force all variable expansion to use the CMD syntax (which requires a leading and trailing %).
<DIR>
</DIR>
 
Aug 16, 2008
124
0
So Microsoft is not following its own rules by including characters which are not valid as variable names? Or does it just not follow TCC's rules?

Anyway, the %[] is very good advice.

Thanks, Thorsten
 
So Microsoft is not following its own rules by including characters which are not valid as variable names?
Who knows, since I don't suppose it is documented anywhere and even Windows XP lets me create variables with brackets in the name. Under CMD it will never be an issue (because you have to close the variable name with a second percent sign) but 4DOS et al have always worked differently. The thing that really bugs me is why include the brackets at all, since ProgramFilesx86 would be just as sensible a name.
 
Similar threads
Thread starter Title Forum Replies Date
nikbackm TCC 20 variable expansion bug Support 6
rfaquino WAD Apparently a bug when expanding environment variable %ProgramFiles(x86) Support 2
Dick Johnson v28 Cosmetic Bug Support 0
Jay Sage WAD Possible Bug With OPTION Command With @FILE Support 5
R strange bug? Support 7
Jay Sage Bug With Flow Control and/or Command Grouping Support 2
M Server 2019 Bug with @execstr? Support 14
R bug _ypixels in BDEBUGGER Support 6
E Fixed Bug with DIR /Z displaying descriptions Support 8
E Text copy bug Support 1
x13 SETARRAY /Z bug Support 6
Gamegod ffind bug with chinese Support 2
Dick Johnson cdd - is this a bug or a feature? Support 7
P "Set" command behavior - a bug? Support 3
gentzel Bug launching external commands in 20.11.43 Support 11
R Is this a bug in SETARRAY? Support 2
M Windows Installer bug? Support 4
vefatica @SCRIPT bug persists Support 4
M Little bug, big consequences .. Support 6
fishman@panix.com Once again the Can't Install bug bites... Support 2
gentzel Fixed dirs +n bug in 20.0.12 x64 Support 2
M Bug in Windows 10, when adding symbol to task bar Support 6
Alpengreis [Bug?] View (V) Prefs Error (TC 18.00.27 x64) Support 4
D WAD Minor Post Installation Bug in V18 Support 1
I Possible Bug: History /n Returns Nothing Support 3
samintz WAD Weird REN bug Support 6
Jay Sage WAD Possible Bug in Batch Parameters Support 7
G Bug? TCC 16.03.55 Console Palette Support 4
S Return of FTP copy bug in 16.02.48 Support 12
S XenForo bug Support 3
D TCMD16 Delete Toolbar Button bug Support 7
keithg1964 WAD 16.0027 Alias /rz bug Support 8
T Documentation @LINE[CON,n] @LINES[CON] not documented (bug?) Support 4
H TIMER bug Support 4
G Fixed @REREPLACE bug Support 15
G WAD PDIR @IF bug, @WORD bug Support 8
T Bug in TCMD but not in TCC Support 8
M WAD A complaint regarding a very irritating TCC installation behavior... (Bug?) Support 4
nickles Renaming bug? Support 9
nickles Redirect bug? Support 4
nickles UrlDecode() bug? Support 3
P WAD Bug in TC v 13.03 build 39 x64 Support 1
S Debug feature bug? Support 17
Roedy CDD /S bug Support 3
J TCCLE 12.11 dirhistory bug Support 1
S MOVE from FTP directory to another FTP directory - bug?? Support 2
M An undocumented limitation and an associated minor bug... Support 1
M High-Precision arithmetic bug... Support 1
nickles REN bug Support 11
Y 12.1 Bug ? Support 2

Similar threads