The environment is mapped through the global env array in Tcl. The keys and default values โโof the array for the environment inherited from the parent process, any process that creates Tcl will inherit a copy of it, and code that examines the environment in the current process (including directly from C) will see its current state.
Choosing the environment installed in the shell script is quite complicated. The problem is that .bashrc (for example) can do quite complex things, as well as set many environment variables. For example, it can also print a message of the day or conditionally take action. But you can at least make a sensible attempt using the shell env command:
set data [exec sh -c "source /path/to/file.sh.rc; env"] # Now we parse with some regular expression magic foreach {- key value} [regexp -all -inline {(?wi)^(\w+)=((?!')[^\n]+|'[^']+')$} $data] { set extracted_env($key) [string trim $value "'"] }
This is pretty awful and not quite right (there are things that can confuse him), but it's pretty close. Values โโwill be populated in the extracted_env array.
I find it easier to get people to set things up with Tcl scripts ...
source share