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

SignUp Now!

Read-only environment variables wiped by SETLOCAL / ENDLOCAL

Charles Dye

Super Moderator
Staff member
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.

C:\>set /ro test=1

C:\>set test=2

C:\>set test

C:\>type wipeout.btm


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

C:\>set test=Something

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


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.
It works as I would expect in build 51.

The read-only status is still not inherited by child shells, though. WAD?
WAD. The read-only list is not passed to "child shells" (a hopelessly obsolete concept from the halcyon days of MS-DOS). If you really want it, you can submit to the feedback forum.

I don't have a strong opinion either way. I don't even know what that feature's for, really.

Similar threads