Problem with variable names with embedded period

May 20, 2008
3,515
4
Elkridge, MD, USA
It seems that under many circumstances the parser considers a period
embedded in the name of an environment variable as a name terminator. Some
instances I found are:

[c:]set setcolor.lst=aa bb cc
[c:]set setcolor=xxx

1/ using the VariableExpand key in the command line

[c:]xyz %setcolor.lst

displays

[c:]xyz xxx.lst

2/ ECHO

[c:]echo %setcolor.lst
xxx.lst

3/ In a batch file the command

do %x in /l %setcolor.lst
echo %x
enddo

displays .lst



IF DEFINED works correctly, i.e., if SETCOLOR is not defined, IF DEFINED
SETCOLOR.LST is true.

The behavior goes back at least to V6. I never observed it, because I only
use a few such variable names, and those only with IF DEFINED tests (not
counting executable extensions).
--
Steve
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,426
85
Albuquerque, NM
prospero.unm.edu
It seems that under many circumstances the parser considers a period embedded in the name of an environment variable as a name terminator. Some instances I found are:

The preferred characters for variable names are alphanumerics, dollar sign, and underscore. Adding the period to the list would wreak havoc on a large number of batch files....
 
May 20, 2008
3,515
4
Elkridge, MD, USA
Charles Dye wrote:
| ---Quote (Originally by Steve Fábián)---
| It seems that under many circumstances the parser considers a period
| embedded in the name of an environment variable as a name terminator.
| Some instances I found are: ---End Quote---
| The preferred characters for variable names are alphanumerics, dollar
| sign, and underscore. Adding the period to the list would wreak
| havoc on a large number of batch files....

You are correct that the period is NOT listed as a "standard" character, and
HELP topic "environment.htm" specifies that period and other characters can
be used in variable names that are expected to be expanded by enclosing the
names in brackets, which I failed to do. I failed to RTFM...

However, though rarely used nowadays, PKZIP.EXE uses the variable PKZIP.CFG
to find the directory where its configuration file is, even in the
COMMAND.COM environment. Defining executable extensions also requires
variable names starting with period. I never had trouble defining and using
them, but none of these variables are normally expanded at the command line
or in batch programs.
--
Steve
 

rconn

Administrator
Staff member
May 14, 2008
12,319
148
Steve Fábián wrote:

> It seems that under many circumstances the parser considers a period
> embedded in the name of an environment variable as a name terminator.

It goes back to v1 -- a period is not and never has been a valid
character in a variable name.

If you're really determined (and don't mind breaking most of the batch
files in existence), you can force it with the %[] syntax.

Rex Conn
JP Software
 
May 20, 2008
3,515
4
Elkridge, MD, USA
rconn wrote:
| Steve Fábián wrote:
|
|
| ---Quote---
|| It seems that under many circumstances the parser considers a period
|| embedded in the name of an environment variable as a name terminator.
| ---End Quote---
| It goes back to v1 -- a period is not and never has been a valid
| character in a variable name.
|
| If you're really determined (and don't mind breaking most of the batch
| files in existence), you can force it with the %[] syntax.

I already admitted that I did not RTFM before posting the original message,
and that there are no problems in 4NT or TCC operation. However, as a
theoretical issue, if you consider period to be invalid in variable names,
why does the syntax defining executable extensions require the creation of
variables with period as first character of their name?
--
Steve
 

rconn

Administrator
Staff member
May 14, 2008
12,319
148
Steve Fábián wrote:

> rconn wrote:
> | Steve Fábián wrote:
> |
> |
> | ---Quote---
> || It seems that under many circumstances the parser considers a period
> || embedded in the name of an environment variable as a name terminator.
> | ---End Quote---
> | It goes back to v1 -- a period is not and never has been a valid
> | character in a variable name.
> |
> | If you're really determined (and don't mind breaking most of the batch
> | files in existence), you can force it with the %[] syntax.
>
> I already admitted that I did not RTFM before posting the original message,
> and that there are no problems in 4NT or TCC operation. However, as a
> theoretical issue, if you consider period to be invalid in variable names,
> why does the syntax defining executable extensions require the creation of
> variables with period as first character of their name?

So that they couldn't possibly be confused with an environment variable.
(Just like the current working directory variables, which begin with a
'=' and are hidden from view.)

Rex Conn
JP Software
 
May 20, 2008
11,300
95
Syracuse, NY, USA
On Wed, 19 Nov 2008 20:59:12 -0600, Steve Fábián <> wrote:


>rconn wrote:
>| Steve Fábián wrote:
>|
>|
>| ---Quote---
>|| It seems that under many circumstances the parser considers a period
>|| embedded in the name of an environment variable as a name terminator.
>| ---End Quote---
>| It goes back to v1 -- a period is not and never has been a valid
>| character in a variable name.
>|
>| If you're really determined (and don't mind breaking most of the batch
>| files in existence), you can force it with the %[] syntax.
>
>I already admitted that I did not RTFM before posting the original message,
>and that there are no problems in 4NT or TCC operation. However, as a
>theoretical issue, if you consider period to be invalid in variable names,
>why does the syntax defining executable extensions require the creation of
>variables with period as first character of their name?

I don't think it's "invalid"; it's just special (and thus may need the %[]
treatment). That's for a very good reason ... so you can do the likes of
"%basename.txt". You wouldn't want to be required to say "%[basename].txt",
would you?

As for variables whose first character is "." they're special (in a way); what
precedes the "." is an empty string and an empty string can't be the name of an
environment variable.

These are trade-offs for ease of use and I think 4NT does a pretty good job
here.
 
Similar threads
Thread starter Title Forum Replies Date
Frank problem with environment variable x86 vs. x64 Support 2
fishman@panix.com Problem with 27.15 Support 2
M Problem with VSDevCmd.bat in VS 16.7.3 Support 0
R Problem with @INT[ value] in V26 Support 9
M Selecting test "off by one" problem in Take command Support 4
Alpengreis UTF-8 problem in TCC related to Python Support 7
K_Meinhard Small problem in german IDE 26 Support 3
B Problem with color in nested shells Support 1
Joe Caverly Problem creating and switching to a DESKTOP Support 9
vefatica Another popup problem Support 10
Alpengreis ffind dialog (/W) problem Support 4
Alpengreis [TCMD v25.00.24] Small space problem with the DE translation in Prefs-GUI Support 1
Alpengreis [TCMD v25.00.24] Problem with copy and paste and the # char via mouse in TCC Support 6
A Problem with functions @int @decimal and identifying Powershell as a shell. Support 12
B IF command problem in tcexit.btm Support 9
fishman@panix.com Problem at Startup of TCC Support 3
P Problem with SFTP copies Support 7
P Problem with FTP copies Support 10
Jay Sage Problem with Context Menu Copy+Paste+Run Key Assignment Support 7
R Problem with %_do_loop in nested do loops Support 2
fishman@panix.com New Problem with later Windows 10 Support 10
Peter Murschall A little problem with LEAVE and COMMENT Support 5
M Handling of %~I problem Support 4
WinLanEm FOR problem Support 18
K Problem With SCRPUT /u Support 3
vefatica What's TCMD's problem with ^e[0m? Support 13
Peter Murschall IDE: RTL with non-English resources-problem is back in Build 28 Support 4
rps Regex problem: \xnn not recognized as a hex character Support 0
rps PRIORITY LOW problem Support 1
old coot Regex problem: \xnn not recognized as a hex character Support 12
vefatica Another problem with build 22. Support 3
Alpengreis [23.x] Download-Problem Support 2
S Problem with " Support 3
C Problem navigating forums Support 11
x13 Problem listing repository files using DIR http(s)://... Support 8
Joe Caverly Problem with TEE in v22 Support 2
Alpengreis Problem with thousands delimiter and colors Support 17
M Take Command 18, migrating to another machine, license problem. Support 1
B TCC 21.01.50 Problem with ALIAS /r and SET /r Support 2
rps How to? @search problem Support 2
WinLanEm @SELECT problem Support 6
T Fixed Problem with use of Batch parameters in the IDE Support 1
Oz Solomon Problem with "list" Support 14
S V21.24 theme problem Support 2
Alpengreis Problem if command prompt is not legacy Support 4
Alpengreis TCMD.INI: The "super hidden" problem ... Support 6
G Odd problem - screen brightness Support 4
rps V20 In-process pipes problem Support 8
Alpengreis Again theme problem [v20.0.21]? Support 11
WinLanEm INPUT problem Support 1

Similar threads