1

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 $.

2
  • 2
    Note on bash. You do not need to assign A to A on export. If the variable is already defined, just export A exports it into the environment. As for Tcl, I do not do Tcl, but puts "A == $::env(A)" seems to have worked for me. Commented Jun 27, 2018 at 20:53
  • 1
    They can all be exported in one line: export A B C. Then they will be in the child process's environment block regardless of the language. Commented Jun 27, 2018 at 21:23

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

thx @glennjackman, the example was meant to come out different, as Donal has posted in the meantime ...
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.