Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

WAD Set statements in () causes problems

Apr
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%"
 
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.
 
I use spaces after '(' and before ')' all the time. Can't you put that one in "Duplicate CMD bugs"?
 
... 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.
 
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.
 
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
   ()
)
 
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).
 
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:
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

Replies
4
Views
2K
Back
Top