Fixed Set "VAR=VAL" format causes problems

Apr 7, 2010
42
0
I've attached a batch file that is causing problems under TCMD. The file does not set variable VAR as expected; the output is:
****
**
***


If I do nothing more than uncomment the 'echo HERE' line at line 11, the output changes to
HERE
****
** aaa
***


I suspect the problem lies in the format to the SET VAR command at line 10.
This SET "VAR=VAL" command, with the enclosing quotes, is a common construct is Microsoft's batch files. (My test file is based on the structure of the :print_vscmd_header in the VsDevCmd.bat file in Visual Studio 17.) This same construct is used in several places in MSVS's batch files.

It is also used in several places in Anaconda's python virtual environment scripts.

If I'm correct in that the problem is caused by the placement of the quotes in the SET command, could you add support for it? In earlier versions of MSVS, I think I needed to change just one place in MS's batch files to get it to work under TCMD. But with the latest release of MSVS, it is much more of a problem.

NOTE: I categorized this as a bug, because even if you did not intend to support the SET "VAR=VAL" construct; simply adding an echo should not change the variable's value.
 

Attachments

  • mytest2.bat
    220 bytes · Views: 105
Dec 7, 2009
238
2
Left Coast, USA
Having written and viewed batch files (and now .btm files) since the early days, I don't recall ever having seen a "set" command taking that form — with the quotation-marks.

For about 15 years I worked at the Evil Empire itself. There were lots of .bat files to be seen there (for some reason C++ developers are enamored of them). In fact one department had an entire build process composed entirely of interlocking .bat files. I had occasion to look at them a number of times and years later still haven't recovered from the experience. Many "set" statements to be seen in all of those .bat files — none containing the quote-marks.

What is the purpose or advantage to the quotation-marks? Would TCC users benefit from being able to use them? Or to look at it another way: what loss might there be in not using them?
 

samintz

Scott Mintz
May 20, 2008
1,503
16
Solon, OH, USA
I vaguely recall an earlier discussion around this. I would be very surprised if support for it was not already in the product. Do you have "Duplicate CMD.EXE Bugs" enabled in TCC?
 
Dec 7, 2009
238
2
Left Coast, USA
(for some reason C++ developers are enamored of them).
To clarify: I used to show them .btm files and how much more they offered. Typical developer response: "Nah, I can do that with a batch file [meaning .bat or .cmd]" even though the 4NT and later TCC script commands shown would never be easily do-able with a simple cmd.exe .bat or .cmd file. Like the man said: Oh, well.
 
May 20, 2008
11,432
99
Syracuse, NY, USA
I don't think it's the SET command. SET does support that syntax. It has something to do with IF and the parentheses. These work:

Code:
if "%VAR_ALT%"=="" set "VAR=aaa"

if "%VAR_ALT%"=="" (set "VAR=aaa" & rem)

And this doesn't work:
Code:
if "%VAR_ALT%"=="" (set "VAR=aaa")
 
Apr 7, 2010
42
0
@vefatica
But, in the script I uploaded, if I change only line 10 to: set VAR=aaa (without the quotes) and the ECHO at line 11 is still commented out, it works. I still think it is a problem with the quotes in the SET command.
 
May 20, 2008
11,432
99
Syracuse, NY, USA
@vefatica
But, in the script I uploaded, if I change only line 10 to: set VAR=aaa (without the quotes) and the ECHO at line 11 is still commented out, it works. I still think it is a problem with the quotes in the SET command.
Yes, I knew that. It's certainly not SET alone, but some odd interaction of SET with IF and parentheses.
 
Apr 7, 2010
42
0
@vefatica
Yes, you are right. It does seem to be some combination of SET and IF. I had not really considered the IF portion of it. So, it does seem to be a bug, then.
 
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 WAD Set statements in () causes problems Support 8
M How to? How to set a default TITLE for newly opened tab? Support 2
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