WAD Set statements in () causes problems

Apr 7, 2010
42
0
I just updated to Version 21.01.57. But I'm still having problems with parenthesis after variables adding a space to the values.

This command correctly prints: "a"
Code:
if "1"=="1" (SET _result=a)
echo "%_result%"
This command incorrectly prints "a ", with an added space.
Code:
if "1"=="1" (SET _result=a
)
echo "%_result%"
 

rconn

Administrator
Staff member
May 14, 2008
12,340
149
This is a CMD-compatibility change to match what CMD does with trailing whitespace in a SET inside a command group. (Yes, I know, but complain to Microsoft ...)

Something like:

(set result=a )

is not the same as

(set result=a)

I presume this is a bug (it's undocumented and there's no rational reason to do it, as you can accomplish the same thing by using double quotes). But I had several complaints that TCC couldn't run some Microsoft batch files because MS expected to find the trailing whitespace.
 
May 20, 2008
11,379
98
Syracuse, NY, USA
I use spaces after '(' and before ')' all the time. Can't you put that one in "Duplicate CMD bugs"?
 
Apr 7, 2010
42
0
... but...but if I run the same commands in CMD, both print "a", with no added space.

The reason this is causing problems, is that I am unable to run MS's vcvarsall.bat under TCMD. When the batch file sets a variable to a directory path, TCMD adds a space to the variable, CMD does not.
 
Apr 7, 2010
42
0
Also, if I understand you correctly, the following code would set result to "a " but instead it's set to "a".
Code:
(set result=a
set b=1)

It only adds a space if the closing ")" is on a new line and there is no other statement after the "set result=a" statement.
 
Apr 7, 2010
42
0
For anyone else having difficulty running existing scripts (like MS's or Anaconda's), a workaround is to change any conditional or loop constructs like
Code:
(
   set A=B
)
to
Code:
(
   set A=B
   ()
)
 
May 20, 2008
11,379
98
Syracuse, NY, USA
Or,
Code:
if "1" == "1" (set "zzz=xxx"
)

And, with the ')' on the next line, I don't see CMD adding the space (unless I've added it myself).
 
Apr 7, 2010
42
0
Yes, I agree. TCMD seems to be adding a space that is not present in the command.
There is a newline after the 'set a=b' not a space. But TCMD sets a equal to 'b '. It adds a space.

Code:
(
    set a=b
)

But, even if there were trailing spaces, I think TCMD should trim them. I think CMD trims trailing spaces before new lines. A space would be included only if followed by a quote, like in your example.

But I could be wrong.
 
Last edited:

rconn

Administrator
Staff member
May 14, 2008
12,340
149
It's worse (much worse) than you think. I used to think that CMD's FOR had the most appalling syntax, but SET has it beat by a mile.

The internal commands in CMD all have their own parser, which makes for at best an uneven and unexpected experience. One of the goals of 4DOS / 4NT / TCC was to use a unified parser with consistent syntax (albeit with a handful of ugly kludges thrown in to match CMD bugs that have inexplicably become "features").

But SET has at least *two* parsers (incompatible with each other), and I strongly suspect given some odd behavior I haven't been able to fully define yet that there is at least one more. Depending on how & where you use SET, and what arguments you provide, SET will either:
  1. Preserve all trailing whitespace
  2. Trim all trailing whitespace
  3. Add one trailing space
  4. Add two trailing spaces
  5. Truncate non-whitespace characters
And let's not even get started on the times that SET deletes whitespace in the middle of the argument.

I've tried to preserve as much compatibility with CMD behavior as possible without screwing up TCC features, but the erratic trailing whitespace behavior in CMD is pushing it too far. I've decided for build 21.01.58 and later to drop trying (when in TCC mode) to support it unless you use the (somewhat documented) quote behavior:

set "var=abc "

If you set CMD compatibility mode you'll still get all of the awful, unexpected and thoroughly misconceived CMD behavior.
 
Similar threads
Thread starter Title Forum Replies Date
V Set path permanently from within TCC? Support 3
S Debugger keeps breaking with no break point set. Support 1
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
R How to? Set default application in a special folder Support 4
A How to? Set up SMTP password in TCC-RT Support 1
vefatica WAD More SET /A woes Support 4
vefatica SET /A and multidimensional array. Support 1
M How to set Path variable for non-executable file extensions in 4DOS Support 8
D Need to set Take Command font size when switching to high DPI display Support 0
P "Set" command behavior - a bug? Support 3
M How to? Set the ribbon titles to mixed case Support 1
X How to set %_INIREAD result to variable Support 5
M How to? How to set a default TITLE for newly opened tab? Support 2
M Fixed Set "VAR=VAL" format causes problems Support 12
vefatica SET /A var=expression=digits Support 3
cxxl Set encoding for batch file Support 4
B TCC 21.01.50 Problem with ALIAS /r and SET /r Support 2
vefatica SET /A var\=...? Support 10
dcantor Documentation SET /T: missing from heading Support 0
fpefpe Documentation Set /v Support 4
vefatica What's SET /Z? Support 1
R Fixed set /r has stopped working in build 35 Support 4
BeechComer Debugger: how to set %1 variable? Support 3
fpefpe How to? Global variable set /v Support 4
fpefpe Documentation Can the title line of tcmd be set? Support 4
J How to set working directory Support 10
Jay Sage Failure of ACTIVATE to Set a Window Position Support 3
rps Fixed Win "set /p" not working in V17 build 53 Support 3
vefatica SET /A "var%=N", TCC vs. CMD Support 0
J Set environment variable from stdout of command Support 3
B How to? Pre-set _tcfolder on startup when Folders is set Auto-Hide Support 6
Dan Glynhampton Fixed @version "force" flag not working, and unable to set separator Support 3
R WAD /= size ranges not set correctly Support 5
S How to? Set the timestamp of ZIP command built archive to match latest member Support 8
Mordachai Help! How to set parameters for script I'm debugging?! Support 6
Roedy SET= Support 2
A How to? Set up a log file for all command output Support 3
M Fixed character set in dir/copy Support 3
Phileosophos Fixed TakeCommand exits upon "set [" command Support 14
R How to set comspec to point to cmd.exe? Support 5
S WAD SET problem - array element initialization Support 11
C Wildcard expansion in FOR set Support 27
vefatica SET question Support 16
T Set 1% then Echo 1% Support 9
S SET /A question; HELP nits Support 8
noahcoad copy /w to FTP does not set time stamp Support 1
M A request for a new feature for the "set" command... Support 5
cgunhouse Accessing variables set using SET /U or SET /S Support 3
D Force For to treat set of values as text, not files Support 3
vefatica Regular expressions in FOR's set? Support 10

Similar threads