TCC-Option for EnableDelayedExpansion (!var!) problem

Jan 12, 2014
522
11
Switzerland, SO
I have problems with this option. For me it makes no different, if it's enabled or disabled.

I means this ...

TCC_CMD_ExpVar.JPG TCC_CMD_ExpVar_HLP.JPG

So I decide to make the some tests with the following results ...

Example 1

ex1_test-a.cmd:
Code:
@echo off
setlocal
:: count to 5 storing the results in a variable
set _tst=0
FOR /l %%G in (1,1,5) Do (echo [%_tst%] & set /a _tst+=1)
echo Total = %_tst%


ex1_test-b.cmd:
Code:
@echo off
setlocal EnableDelayedExpansion
:: count to 5 storing the results in a variable
set _tst=0
FOR /l %%G in (1,1,5) Do (echo [!_tst!] & set /a _tst+=1)
echo Total = %_tst%


Within CMD, I it gives the following results:

cmd /k "c:\users\alpen\downloads\ex1_test-a.cmd":
Code:
[0]
[0]
[0]
[0]
[0]
Total = 5


cmd /k "c:\users\alpen\downloads\ex1_test-b.cmd":
Code:
[0]
[1]
[2]
[3]
[4]
Total = 5


Within TCC, I it gives the following results - REGARDLESS it the option is enabled/disabled:


tcc /k "c:\users\alpen\downloads\ex1_test-a.cmd":
Code:
[0]
[1]
[2]
[3]
[4]
Total = 5


tcc /k "c:\users\alpen\downloads\ex1_test-b.cmd":
Code:
[0]
[1]
[2]
[3]
[4]
Total = 5



Example 2

ex2_test-a.cmd:
Code:
@echo off
Setlocal
Set _var=first
Set _var=second& Echo %_var% !_var!


ex2_test-b.cmd:
Code:
@echo off
Setlocal EnableDelayedExpansion
Set _var=first
Set _var=second& Echo %_var% !_var!


Within CMD, I it gives the following results:

cmd /k "c:\users\alpen\downloads\ex2_test-a.cmd":
Code:
first !_var!


cmd /k "c:\users\alpen\downloads\ex2_test-b.cmd":
Code:
first second


Within TCC, I it gives the following results - REGARDLESS it the option is enabled/disabled:


tcc /k "c:\users\alpen\downloads\ex2_test-a.cmd":
Code:
second second


tcc /k "c:\users\alpen\downloads\ex2_test-b.cmd":
Code:
second second



Example 3

ex3_test-a.cmd:
Code:
@echo off
c:
cd %temp%
Setlocal
Set _html=Hello^>World
Echo %_html%


ex3_test-b.cmd:
Code:
@echo off
c:
cd %temp%
Setlocal EnableDelayedExpansion
Set _html=Hello^>World
Echo !_html!



Within CMD, I it gives the following results:

cmd /k "c:\users\alpen\downloads\ex3_test-a.cmd":

Creates a file in %temp% DIR with string = Hello

cmd /k "c:\users\alpen\downloads\ex3_test-b.cmd":
Code:
Hello>World


Within TCC, I it gives the following results - REGARDLESS it the option is enabled/disabled:

tcc /k "c:\users\alpen\downloads\ex3_test-a.cmd":

Creates a file in %temp% DIR with string = Hello

tcc /k "c:\users\alpen\downloads\ex3_test-b.cmd":

Creates a file in %temp% DIR with string = Hello


Is something not correct with this option or do I missunderstand something?

PS: TC 19.0.27 x64 on Win 10 Pro x64
 
May 20, 2008
12,171
133
Syracuse, NY, USA
They do act differently, even in the simplest of tests.
CMD:
Code:
V:\> set var=Hello^>World

V:\> echo !var!
Hello>World

V:\>

TCC (with "Delayed expansion" checked):
Code:
v:\> set var=Hello^>World

v:\> echo !var!

v:\> type World
Hello

v:\>
 

rconn

Administrator
Staff member
May 14, 2008
12,557
167
Within TCC, I it gives the following results - REGARDLESS it the option is enabled/disabled:

tcc /k "c:\users\alpen\downloads\ex1_test-a.cmd":
Code:
[0]
[1]
[2]
[3]
[4]
Total = 5


tcc /k "c:\users\alpen\downloads\ex1_test-b.cmd":
Code:
[0]
[1]
[2]
[3]
[4]
Total = 5

WAD - in TCC, nested variable expansion is enabled by default. If you want to turn it off, you have to do two things:

1) SETDOS /x4
2) go to OPTION / Startup and uncheck "CMD.EXE delayed expansion".
 

rconn

Administrator
Staff member
May 14, 2008
12,557
167
TCC doesn't treat %var% and !var! differently (until recently, neither did CMD). I don't know that there's any value in crippling TCC's variable expansion to match CMD's. But if you want to have a mix of nested and non-nested variable expansion on a command line, you can certainly submit a suggestion in the Feedback forum. If other users support the idea I will consider adding it in a future version.
 

rconn

Administrator
Staff member
May 14, 2008
12,557
167
Example 2

Within TCC, I it gives the following results - REGARDLESS it the option is enabled/disabled:

tcc /k "c:\users\alpen\downloads\ex2_test-a.cmd":
Code:
second second


tcc /k "c:\users\alpen\downloads\ex2_test-b.cmd":
Code:
second second

WAD - see my previous message about SETDOS /X4 and "CMD.EXE delayed expansion".

Note that TCC (actually 4NT at that time) had nested variable expansion about 12 years before CMD. Changing TCC to emulate CMD's somewhat demented expansion syntax would break a LOT of TCC batch files & aliases.
 

rconn

Administrator
Staff member
May 14, 2008
12,557
167
They do act differently, even in the simplest of tests.
CMD:
Code:
V:\> set var=Hello^>World

V:\> echo !var!
Hello>World

V:\>

While that's a mildly amusing CMD bug, I don't know that it's anything I would care to emulate.

In CMD (with delayed expansion enabled), try:

set var=Hello^>World
echo %var%
echo !var!

And then explain to me why CMD's behavior is a good thing. In this (non simple) example, the value of VAR in the environment is identical in CMD and TCC. What's different is how CMD expands the variable.
 
Jan 12, 2014
522
11
Switzerland, SO
@rconn

Ah, ok - thank you very much for explaining!

PS: Have a HAPPY NEW YEAR and thank you for the always good support here and for Take Command itself!
PPS: I wish also a Happy New Year to all others here of course!
 
May 20, 2008
12,171
133
Syracuse, NY, USA
In CMD (with delayed expansion enabled), try:

set var=Hello^>World
echo %var%
echo !var!

Nothing surprising there. What was I supposed to see?
Code:
C:\Users\vefatica> set var=Hello^>World

C:\Users\vefatica> echo %var%

C:\Users\vefatica> echo !var!
Hello>World
 

rconn

Administrator
Staff member
May 14, 2008
12,557
167
Nothing surprising there. What was I supposed to see?
Code:
C:\Users\vefatica> set var=Hello^>World

C:\Users\vefatica> echo %var%

C:\Users\vefatica> echo !var!
Hello>World

You expected the same variable to be displayed differently? Look in the environment; the variable is "var=Hello>World". There isn't even any nested variable expansion taking place here; the !var! format doesn't result in any redirection after the expansion. Why?
 
May 20, 2008
12,171
133
Syracuse, NY, USA
You expected the same variable to be displayed differently? Look in the environment; the variable is "var=Hello>World". There isn't even any nested variable expansion taking place here; the !var! format doesn't result in any redirection after the expansion. Why?

I don't know how CMD does that and I'm not suggesting you emulate it. Maybe every CMD internal command has a parser to expand !var![exclamation point]
 

Similar threads