Difference between TCC and CMD: variable names with hyphens

Oct 18, 2009
342
15
In TCC 22, 32-bit a difference between TCC and cmd:

Set DEN_a-temp="Hello"

Echo %DEN_a-temp

TCC: -temp
CMD: %DEN_a-temp ( WAD )

Echo %DEN_a-temp%

TCC: -temp
CMD: "Hello"

In the actual usage the variable name stands for "a file with Insurance Denial records in the temporary-hold folder \a-temp". The folder is named "a-temp" so it will display first in File Manager. The data the variable actually holds is a path ending with a slash.
 
May 20, 2008
10,573
78
Syracuse, NY, USA
Try "OPTION //CmdVariables=Yes".

Code:
v:\> echo %[a-b]
"Hello"

v:\> echo %a-b%
-b

v:\> echo %a-b
-b

v:\> option //cmdvariables=Yes

v:\> echo %[a-b]
"Hello"

v:\> echo %a-b%
"Hello"

v:\> echo %a-b
"Hello"
 

rconn

Administrator
Staff member
May 14, 2008
11,910
133
A '-' is technically not a valid variable name character. CMD doesn't care because it requires leading & trailing %'s to delineate the name. TCC only requires the leading character -- unless you want to use an invalid character. Then, either use %[…] or turn on CMDVariables (which will then require ALL variables to have leading & trailing %'s).
 
Oct 18, 2009
342
15
I found this in the Help, which explains the behavior:

TCC Variables and Functions

"The environment variable names you use this way may contain any alphabetic or numeric characters, the underscore character _, and the dollar sign $. You can force acceptance of other characters by including the full variable name in square brackets, like this: %[AB##2]. You can also indirectly reference environment variables using square brackets. For example %[%var1] means "the contents of the variable whose name is stored in VAR1".
...
The trailing percent sign that was traditionally required for environment variable names is not usually required by TCC, which accept any character that cannot be part of a variable name as the terminator. However, the trailing percent can be used to maintain compatibility with CMD."

--------------------------
When I saw the code wasn't working I realized TCC was probably treating it as math and was trying to subtract temp from DEN_a, but I was surprised that when I added a closing % TCC didn't consider DEN_a-temp to be a variable name.
 
Aug 23, 2010
581
7
I'm using "%[…]" syntax personally to increase compatibility with TCC itself (i.e. reduce any doubt about what is considered variable's name).