1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

TCC-Option for EnableDelayedExpansion (!var!) problem

Discussion in 'Support' started by Alpengreis, Dec 27, 2015.

  1. Alpengreis

    Joined:
    Jan 12, 2014
    Messages:
    229
    Likes Received:
    6
    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
     
  2. Alpengreis

    Joined:
    Jan 12, 2014
    Messages:
    229
    Likes Received:
    6
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    Sorry, I don't use it and I don't know how it should work. Delayed expansion is needed in CMD (see CMD's "SET /?"). It's not needed in TCC so I don't care about it.
     
  4. Alpengreis

    Joined:
    Jan 12, 2014
    Messages:
    229
    Likes Received:
    6
    Ok, no problem, thank you. I have to wait for Rex then probably ...
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    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:\>
     
  6. Alpengreis

    Joined:
    Jan 12, 2014
    Messages:
    229
    Likes Received:
    6
    Thanks, Vince! The question is now: is this WAD?
     
  7. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    That's a question for Rex. I'd hate to see TCC bogged down with more CMD compatibility; it's not important to me. Is it important to you, Alpengreis?
     
  8. Alpengreis

    Joined:
    Jan 12, 2014
    Messages:
    229
    Likes Received:
    6
    Well. Not for MY scripts. But I have eventually other scripts to execute with such things. As long as I execute such with CMD it's no problem ...
     
  9. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,804
    Likes Received:
    82
    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".
     
  10. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,804
    Likes Received:
    82
    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.
     
  11. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,804
    Likes Received:
    82
    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.
     
  12. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,804
    Likes Received:
    82
    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.
     
  13. Alpengreis

    Joined:
    Jan 12, 2014
    Messages:
    229
    Likes Received:
    6
    @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!
     
  14. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    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
     
  15. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,804
    Likes Received:
    82
    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?
     
  16. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    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]
     

Share This Page