Read-only environment variables wiped by SETLOCAL / ENDLOCAL

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,483
44
Albuquerque, NM
prospero.unm.edu
#1
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.