Fixed Change in behavior of variable expansion between 16 and 17

Aug 21, 2014
18
1
I had some scripts that was similar to this that did not close a variable in a set statement that stopped working in TCC 17.

Here is a simple batch files that gets the path of the script and removes the trailing backslash:
Code:
rem Get the path from our script and remove the trailing \
set ROOT_DIR=%~dp0
set ROOT_DIR=%ROOT_DIR:~0,-1%
echo Root is %ROOT_DIR%

On cmd.exe (Windows 8.1), it does this:
Code:
E:\Temp>test.bat

E:\Temp>rem Get the path from our script and remove the trailing \

E:\Temp>set ROOT_DIR=E:\Temp\

E:\Temp>set ROOT_DIR=E:\Temp

E:\Temp>echo Root is E:\Temp
Root is E:\Temp

On TCC 16 it does the same thing as cmd.exe:
Code:
rem Get the path from our script and remove the trailing \
set ROOT_DIR=E:\Temp\
set ROOT_DIR=E:\Temp
echo Root is E:\Temp
Root is E:\Temp

On TCC 17, it does this and hangs waiting for the user prompt:
Code:
rem Get the path from our script and remove the trailing \
set ROOT_DIR=E:\Temp\

Cancel batch job E:\Temp\test.bat ? (Y/N/A) :
 
Even when you close the variable expansion, it only works if you run it from the directory that the script is in (E:\Temp in the example above). If you run it in another directory (e.g., run E:\temp\test.bat from D:\Temp), then it stops after the first set ROOT_DIR line.
 
Confirmed CMD's substrings expansion isn't working in build 53 (or 27 - had an older install on another PC).

variable substitution still works. i.e. :

Code:
Set ROOT_DIR=%ROOT_DIR:\=%
E:Temp

But of course that replaces all backslash chars with nothing. Just showing that it works. :)

For now in the few I have that don't immediately spawn CMD for their work (most where re-written as BTMs long ago but had a few that were just too big to change or re-write everything that would need changing - and used by others without TCMD) I have changed to use something like this to make it work both under CMD and TCC:

Code:
rem Get the path from our script and remove the trailing \
set ROOT_DIR=%~dp0
If NOT "%@EVAL[1+1]" == "2" (
  set ROOT_DIR=%ROOT_DIR:~0,-1%
  Goto :Bye
) Else (
If "%@RIGHT[1,%ROOT_DIR]" == "\" Set ROOT_DIR=%@LEFT[-1,%ROOT_DIR]
)
:Bye
echo Root is %ROOT_DIR%
 

Similar threads