Tcl Source Code

View Ticket
Login
Ticket UUID: 8014353dcbac77b8d0c2ad4d1be43603b48fa6c7
Title: append env(varname) overwrites existing value
Type: Bug Created on: 2026-04-26 11:04:56
Submitter: apnadkarni Assigned to: nobody
Subsystem: 08. Environment Variables Severity: Minor
Priority: 5 Medium Last modified: 2026-05-21 13:43:48
Status: Open Closed by: nobody
Resolution: None Closed on:
Version: 8.6
Description:

As the transcript below shows, appending to an environment variable using the lowercase name when originally stored as uppercase overwrites instead of appending. However,

c:\src\tcltk\wip\tcl\win>set USERNAME
USERNAME=ashok

c:\src\tcltk\wip\tcl\win>tclsh
% set env(USERNAME)
ashok
% append env(username) nadkarni
nadkarni     <--------------- OVERWRITE
% set env(USERNAME)
nadkarni
% exit

c:\src\tcltk\wip\tcl\win>tclsh
% set env(USERNAME)
ashok
% append env(USERNAME) nadkarni
ashoknadkarni     <---------------OK
% set env(USERNAME)
ashoknadkarni
% exit

Curiously, if the value is read previously in lowercase before appending, it all works as expected.

c:\src\tcltk\wip\tcl\doc>tclsh
% set env(username)    <---------------- read using lowercase
ashok
% append env(username) nadkarni
ashoknadkarni          <---------------- then works as expected
% set env(USERNAME)
ashoknadkarni
User Comments:
apnadkarni added on 2026-04-26 11:12:37:

The env manpage states environment variable names PATH and COMSPEC are automatically converted to uppercase. It does not say anything about other environment variables. However,

  • the reported behavior is also seen with PATH

  • even if variables other than the above two are case-sensitive, there is still an inconsistency because in that case setting username should not affect USERNAME.


apnadkarni added on 2026-04-26 11:19:48:
Present in 8.6 as well

apnadkarni added on 2026-05-21 13:43:48:
As per ticket [3057639fff], issues around append/lappend, compiled/uncompiled behavior seem to have been around forever and still exist. This ticket might be related.