Read-only environment variables wiped by SETLOCAL / ENDLOCAL

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,748
110
Albuquerque, NM
prospero.unm.edu
Running a batch file which uses SETLOCAL / ENDLOCAL (i.e. most of them) erases the values of read-only environment variables. It does not, however, reset their read-only status.

Code:
C:\>set /ro test=1

C:\>set test=2

C:\>set test
1

C:\>type wipeout.btm
@setlocal
@endlocal

C:\>wipeout

C:\>set test
TCC: Not in environment "test*"

C:\>set test=Something

C:\>set test
TCC: Not in environment "test*"

C:\>

I note in passing that child shells inherit the values of read-only environment variables, but not their read-only status. I infer that the list of protected variables is not stored in the environment, but somewhere else.

(Edit:) Above in TCC 16.02.48, 32-bit XP. Similar in TCC 15.01.58 and 14.03.59. I guess this is not a feature that anybody uses.
 

Similar threads