I have variables A, B, and C.
I have written
export A=$A
export B=$B
export C=$C
Not sure how to carry the variables over into a tcl script. What I currently have written in the tcl script is
puts "$A == $::env(A)"
puts "$B == $::env(B)"
puts "$C == $::env(C)"
But that doesn't work. I have tried with and without the first $.
Either way is meant to work:
$ export A="a"
$ echo "puts $::env(A)" | tclsh
a
or
$ export B="b"; echo "puts $::env(B)" | tclsh
b
or
$ echo "puts $::env(C)" | C="c" tclsh
c
There are two ways. Either you export the variable (there are a few ways to do that) or you assign it as part of the call to tclsh
. Using export
:
export B="b"
echo 'puts "the B environment variable is $::env(B)"' | tclsh
B="b"
export B
echo 'puts "the B environment variable is $::env(B)"' | tclsh
Assigning as part of the call (NB: no semicolons and the variable assignment is close to the actual call to tclsh
):
echo 'puts "the B environment variable is $::env(B)"' | B="b" tclsh
For anything complex or large, try to avoid passing it via environment variables (or command line arguments). Using files works better in those cases. For anything secret , DO NOT use either command line arguments or environment variables as neither is a secure communication mechanism, but files (with appropriate permissions, including on the containing directory) are sufficiently secure.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.