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

Set 1% then Echo 1%

Discussion in 'Support' started by TonyT, Jun 10, 2011.

  1. TonyT

    Joined:
    May 29, 2011
    Messages:
    17
    Likes Received:
    0
    in CMD.exe

    set T=1%
    Echo %T%

    echos 1%

    same in TCC echos only a 1 , not 1%
    What is going on?
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,300
    Likes Received:
    39
    If you want a literal percent sign, you need to double it:

    Code:
    set T=1%%
    echo %T%
    
    Otherwise, it's interpreted as the start of a variable or function name.
     
  3. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    Charles Dye wrote:
    | Quote:
    | Originally Posted by TonyT
    | in CMD.exe
    |
    | set T=1%
    | Echo %T%
    |
    | echos 1%
    |
    | same in TCC echos only a 1 , not 1%
    | What is going on?
    |
    | If you want a literal percent sign, you need to double it:
    |
    |
    | Code:
    | set T=1%%
    | echo %T%Otherwise, it's interpreted as the start of a variable or
    | function name.

    Rex:
    Could the parser be enhanced to recognize that a single percent sign % which
    is not the terminator of a variable name and which is followed by
    "whitespace" (including EOL) could not be the start of a variable name nor
    function name, and thus it ought to be used literally?
    --
    Steve
     
  4. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    Probably, though it seems like an extremely uncommon edge condition.
     
  5. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    rconn wrote:
    | Quote:
    | Originally Posted by Steve Fabian
    | Could the parser be enhanced to recognize that a single percent
    | sign % which is not the terminator of a variable name and which
    | is followed by "whitespace" (including EOL) could not be the
    | start of a variable name nor function name, and thus it ought to be
    | used literally?
    |
    | Probably, though it seems like an extremely uncommon edge condition.

    It is, but it would remove a difference from CMD. It would not benefit me
    significantly, I have learned to live with current operation.
    --
    Steve
     
  6. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    ?? Aren't you the same guy who's always railing against CMD compatibility??
     
  7. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    rconn wrote:
    | Quote:
    | Originally Posted by Steve Fabian
    | It is, but it would remove a difference from CMD. It would not
    | benefit me significantly, I have learned to live with current
    | operation.
    |
    | ?? Aren't you the same guy who's always railing against CMD
    | compatibility??

    Sure I am - when it makes coding for TCC more complicated, esp. when
    imitating a change in CMD is not backward compatible. OTOH on the extremely
    rare occasion when CMD has a good idea which could be adopted into CMD
    without breaking backward compatibility I am all for it. Of course, this
    specific case would not make TCC coding easier sufficiently that I would ask
    for it for my sake.
    --
    Steve
     
  8. TonyT

    Joined:
    May 29, 2011
    Messages:
    17
    Likes Received:
    0
    | If you want a literal percent sign, you need to double it:

    Code:
    set T=1%%
    echo %T%
    
    | Otherwise, it's interpreted as the start of a variable or function name.

    Thanks for all for help from everybody that posted. Doubling %'s was the hint I needed and I was able to solve my problem just fine now. This was an illustration to a more complicated @EcecStr[] problem I was having and I just kept inserting %'s trial and error until it worked ... 8 %'s in a row to finally get the single % I wanted.

    --
    Tony
     
  9. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,854
    Likes Received:
    83
    And this would definitely NOT be backward compatible -- anyone who's doubled their %'s in TCC for this case would now find that their batch files / aliases are mysteriously broken, and would have to track down and edit them.
     
  10. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    ---- Original Message ----
    From: rconn
    | Quote:
    | Originally Posted by Steve Fabian
    || Sure I am - when it makes coding for TCC more complicated, esp. when
    || imitating a change in CMD is not backward compatible.
    |
    | And this would definitely NOT be backward compatible -- anyone who's
    | doubled their %'s in TCC for this case would now find that their
    | batch files / aliases are mysteriously broken, and would have to
    | track down and edit them.

    Ah! You found a valid issue! So this need to go back to the pile of things where CMD malperforms - it does not do what its documentation claims it does - and thus cannot reliably be duplicated. Tongue in cheek suggestion totally withdrawn!
    --
    Steve
     

Share This Page