Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to set environment variable for parent process (Linux shell) in TCL

523 views
Skip to first unread message

ZeroName

unread,
Feb 14, 2017, 3:16:42 AM2/14/17
to
Dear Sir:

How can i set an environment variable in TCL and the variable can be used in its parent process (for example: csh)?

in csh:
setenv a 123

in tcl:
set env(a) 456

after exiting tcl, i wish the variable, a is "456"

Please help me to solve the problem, thanks~

Colin Macleod

unread,
Feb 14, 2017, 5:28:42 AM2/14/17
to
On Tuesday, 14 February 2017 08:16:42 UTC, ZeroName wrote:
> How can i set an environment variable in TCL and the variable can be used in its parent process (for example: csh)?
>

This cannot be done, in Tcl or any other language. It is a property of unix processes that a child process has no access to the environment of its parent process.

Colin.

Andreas Leitgeb

unread,
Feb 14, 2017, 6:28:58 PM2/14/17
to
There are of course ways around it, if the calling shell expects to receive
environment data from the child.

The child (tcl-script) would then write the environment to stdout (and
nothing else!) and the outer shell (csh is evil; use bourne shells!):

zsh, bash, ksh or sh:
eval "`script.tcl`"

script.tcl:
#!/usr/bin/env tclsh
puts "export FOO; FOO=foo"
puts "export BAR; BAR='sn afu'"

PS: child process is responsible for protecting meta characters and blanks
in the values.
0 new messages