Set 1% then Echo 1%

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#3
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
 

rconn

Administrator
Staff member
May 14, 2008
10,096
85
#4
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.
 
#5
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
 
#7
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
 
May 29, 2011
17
0
Seattle
#8
| 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
 

rconn

Administrator
Staff member
May 14, 2008
10,096
85
#9
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.
 
#10
---- 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