The env
array is what you need:
# if you use env in a procedure, you need to specify it is a global variable
global env
set g_user $env(USER)
Documented at http://tcl.tk/man/tcl8.5/TclCmd/tclvars.htm
题
For example, I would like to use $USER and $HOSTNAME which is defined when I login. however
set g_user [exec echo \$USER]
shows me only an error that \$USER is not recognizable.
解决方案
The env
array is what you need:
# if you use env in a procedure, you need to specify it is a global variable
global env
set g_user $env(USER)
Documented at http://tcl.tk/man/tcl8.5/TclCmd/tclvars.htm