WAD handling variables with $-prefix

Aug 2, 2011
258
4
Berlin, Germany
Hi,

I'm doing some considerations for a script to create a fileage-report.
In preparation for this I'm using variables beginning with the $-sign, which should be allowed
as the help says "The environment variable names you use this way may contain any alphabetic or numeric characters, the underscore character _, and the dollar sign $"
But I have a funny behavior: when I issue the commands at the prompt, they are ok
Code:
C:\Program Files\JPSoft\TCMD13x64 >ver
 
TCC  13.04.63 x64  Windows 7 [Version 6.1.7601]
 
C:\Program Files\JPSoft\TCMD13x64 >plugin
TCC: No plugins loaded
 
C:\Program Files\JPSoft\TCMD13x64 >set    $yearsback=10
 
C:\Program Files\JPSoft\TCMD13x64 >set    $lastindex=%@eval[%$yearsback + 1]
 
C:\Program Files\JPSoft\TCMD13x64 >set    /a $nelements=%$yearsback + 2
12
 
C:\Program Files\JPSoft\TCMD13x64 >set    /a $baseyear=%_year - %$yearsback
2002
 
C:\Program Files\JPSoft\TCMD13x64 >
C:\Program Files\JPSoft\TCMD13x64 >set    $*
$baseyear=2002
$lastindex=11
$nelements=12
$yearsback=10
 
C:\Program Files\JPSoft\TCMD13x64 >
C:\Program Files\JPSoft\TCMD13x64 >unsetarray /q array
 
C:\Program Files\JPSoft\TCMD13x64 >setarray array[%$nelements]
 
C:\Program Files\JPSoft\TCMD13x64 >echo    %@arrayinfo[array,0]
  1
 
C:\Program Files\JPSoft\TCMD13x64 >echo    %@arrayinfo[array,5]
  12
and if I run them as a btm they do not work.
Code:
C:\Program Files\JPSoft\TCMD13x64 >filecount_per_year.btm
echo    on
setlocal
on      break goto end
rem    The environment variable names you use this way may contain any alphabetic or numeric characters,
rem    the underscore character _, and the dollar sign $
set    $yearsback=10
set    $lastindex=1
set    /a $nelements=yearsback + 2
set    /a $baseyear=2012 - yearsback
set    $*
$baseyear=2012
$lastindex=1
$nelements=2
$yearsback=10
unsetarray /q array
setarray array[nelements]
C:\Program Files\JPSoft\TCMD13x64\filecount_per_year.btm [16]  Usage : SETARRAY name[a[,b[,c[,c]]]] [...]
echo    1
  1
echo    0
  0
endlocal
quit

Neither "SET /A" nor "@EVAL" can handle the $variables.
Am I on the wrong track?
 
May 20, 2008
11,400
99
Syracuse, NY, USA
Hmmm!. The character is legal in variable names. Bit "%$" also has a meaning of its own. And the help doesn't say all legally-named variables may be freely de-referenced with "%". There's no problem if you de-reference them with %[]. I wonder what Rex will say.
Code:
v:\> type dollar.btm
echo on
set    $yearsback=10
set    $lastindex=%@eval[%[$yearsback] + 1]
set    /a $nelements=%[$yearsback] + 2
set    /a $baseyear=%_year - %[$yearsback]
set $*
unsetarray /q array
setarray array[%[$nelements]]
echo    %@arrayinfo[array,0]
echo    %@arrayinfo[array,5]
 
v:\> dollar.btm
set    $yearsback=10
set    $lastindex=11
set    /a $nelements=10 + 2
set    /a $baseyear=2012 - 10
set $*
$baseyear=2002
$lastindex=11
$nelements=12
$yearsback=10
unsetarray /q array
setarray array[12]
echo    1
  1
echo    12
  12
 
Aug 2, 2011
258
4
Berlin, Germany
Vince, %[] is a cool idea, but makes it unnecessarry complicated.
Then I would abdicate the dollar-sign.
Perhaps I should use the euro-sign € ;)
 
May 20, 2008
11,400
99
Syracuse, NY, USA
Vince, %[] is a cool idea, but makes it unnecessarry complicated.
Then I would abdicate the dollar-sign.
Perhaps I should use the euro-sign € ;)
Is the Euro symbol readily accessible (wouldn't know here in the states). Do you need a prefix at all?

P.S., The "Frank" image is a bit unnerving but it brings back fond memories and has prompted me to listen (after a long time) to some of the most creative music I can think of.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
There are a few other places where the %[] notation is needed ... IIRC, in "DO x" and "FOR %x" routines, because one-letter variable names have some preference.
 
Aug 2, 2011
258
4
Berlin, Germany
Is the Euro symbol readily accessible (wouldn't know here in the states).
I can access it on my german keyboard with AltGr-E.
Do you need a prefix at all?
No, it's just for having them all togehter with a "set $*". I thought it could be convenient for my little "project" because I fear I will have to check the variables very often;)

P.S., The "Frank" image is a bit unnerving but it brings back fond memories and has prompted me to listen (after a long time) to some of the most creative music I can think of.
I'm very happy I brought FZ back in mind. I am/was a really big fan since I was ~16 years old.
But why is the picture unnerving? Do you think the other forum members could be nerved, too?
Please let me know.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
I'm very happy I brought FZ back in mind. I am/was a really big fan since I was ~16 years old.
But why is the picture unnerving? Do you think the other forum members could be nerved, too?
Please let me know.
Basically because he's no longer with us and I figure if that were not the case **someone** would, today, be making new music that I like. I'm not offended by the image; it just makes me think.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
And just to jog a few more memories, last week, Donovan (as in Donovan Leitch) performed at a jazz festival here in Syracuse, NY.
 
Aug 2, 2011
258
4
Berlin, Germany
I've choosen the picture as a kind of hommage. And sometimes I get the blues, too, if I think of former times :cool:
 
Aug 2, 2011
258
4
Berlin, Germany
what do you think of this version?
Code:
echo    on
setlocal
on      break goto end
 
set    _$yearsback=10
set    _$lastindex=%@eval[%_$yearsback + 1]
set    /a _$nelements=%_$yearsback + 2
set    /a _$baseyear=%_year - %_$yearsback
 
set    _$*
 
unsetarray /q _$array
setarray _$array[%_$nelements]
echo    %@arrayinfo[_$array,0]
echo    %@arrayinfo[_$array,5]
 
endlocal
quit
which doesn't run into the %$ trap:
Code:
echo    on
setlocal
on      break goto end
set    _$yearsback=10
set    _$lastindex=11
set    /a _$nelements=10 + 2
set    /a _$baseyear=2012 - 10
set    _$*
_$baseyear=2002
_$lastindex=11
_$nelements=12
_$yearsback=10
unsetarray /q _$array
setarray _$array[12]
echo    1
  1
echo    12
  12
endlocal
quit
 

rconn

Administrator
Staff member
May 14, 2008
12,344
149
Hi,

I'm doing some considerations for a script to create a fileage-report.
In preparation for this I'm using variables beginning with the $-sign, which should be allowed
as the help says "The environment variable names you use this way may contain any alphabetic or numeric characters, the underscore character _, and the dollar sign $"
But I have a funny behavior: when I issue the commands at the prompt, they are ok

WAD -- see the help for "batch file parameters". %$ has a different meaning in batch files.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,460
88
Albuquerque, NM
prospero.unm.edu
I have a vague memory that the help file once strongly recommended beginning variable names with a letter. Now I can't find it. Was the suggestion removed, or is this just a Fig Newton of my imagination?
 

rconn

Administrator
Staff member
May 14, 2008
12,344
149
I don't know that it was ever in the documentation, but it is definitely a good idea. Variable names beginning with a '_' are assumed to be internal variables (though you can override them with an environment variable, after a wasted search through the internal list), and variables beginning with a number or '$' are treated as batch (or alias) parameters.

If users are suffering from an overwhelming compulsion to use otherwise invalid characters in variable names, they can always use the %[] syntax.
 
Aug 2, 2011
258
4
Berlin, Germany
I don't know that it was ever in the documentation, but it is definitely a good idea. Variable names beginning with a '_' are assumed to be internal variables (though you can override them with an environment variable, after a wasted search through the internal list), and variables beginning with a number or '$' are treated as batch (or alias) parameters.

If users are suffering from an overwhelming compulsion to use otherwise invalid characters in variable names, they can always use the %[] syntax.
Yet a little bit stressed? Not very politely :(
I don't know why I ran into this trap. Normally I do not use any prefixes in my variables.
And I said
Am I on the wrong track?
 
Similar threads
Thread starter Title Forum Replies Date
vefatica WAD TCC: inconsistent character handling Support 11
M Handling of %~I problem Support 4
J File explorer handling from command line? Support 2
forbin Strange handling of [nonbright] magenta background (v22) Support 2
T WAD Difference between TCC and CMD in handling multi-command lines Support 6
thorntonpg Handling files with embedded spaces Support 1
J junction copy/move handling Support 6
C How to? MOVE and handling out of space Support 2
The Wizard WAD Possible Incorrect COMSPEC handling Support 2
BobK How to? Handling filenames with blanks at command line Support 3
A Discrepancy in handling of "can't copy or move file to itself" Support 4
M How to? A question about error-handling... Support 25
S Description handling Support 3
B Strange handling of a .BAT file Support 5
C handling percent signs in filenames Support 2
C handling percent signs in filenames Support 1
S Ctrl-C handling while piping Support 0
vefatica Icon handling in b153 Support 7
U An annoying bug with TCC's icon handling in the taskbar Support 25
p.f.moore Bug in plugin break handling? Support 0
p.f.moore Error handling in plugins Support 2
Peter Murschall v27.00.16/17: ENDLOCAL with exporting variables wipes out the complete Environment Support 2
S How to? best way to compose data for command to use out of presets/variables Support 1
Joe Caverly START Dialog usage of %_ variables Support 0
Joe Caverly Modified Variables in CMDebug/BDebugger Support 1
T How to? Show the values of batch variables on the TCC screen Support 21
J Escaped Characters and Variables Support 2
M Keywords for commands, functions, internal variables Support 3
D How to? How to show variables expanded in the log tab Support 3
Charles Dye Read-only environment variables wiped by SETLOCAL / ENDLOCAL Support 5
U Variables _IFTP, _IFTPS: what about sftp connections? Support 2
J Shell nesting level, and inherited environment variables Support 10
M Verification re volatile variables... Support 41
fpefpe Documentation environment variables Support 3
fpefpe How to? Environment Variables changed Support 2
Stefano Piccardi 14.01.33 unset doesn't complain about undefined variables Support 8
CWBillow Variables in shortcuts? Support 15
daniel347x How to get Take Command to read in all current system environment variables that CMD.EXE sees? Support 13
cgunhouse Accessing variables set using SET /U or SET /S Support 3
vefatica What environment variables does IDE need? Support 3
G gosub variables Support 9
vefatica Leading spaces in array variables Support 13
E Environment variables, set and input Support 2
S How to? Change thread prefix? Easy "create thread" method? Support 8

Similar threads