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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top