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

Passing environment variables from tcl to other sh processes

1,667 views
Skip to first unread message

Chang, Yu Y

unread,
May 28, 1996, 3:00:00 AM5/28/96
to

Hi. I am trying to set an environment variable in Tcl to pass
it a child process. Ousterhout's and Welch's syntax of

set env(VARIABLE) 'whatever'

seems to only set a local tclsh variable called 'env(Variable)',
and not to the shell environment $VARIABLE. Are there quoting
mechanism syntax that I need to include to make the passing of
the environment variables successful?
Any help is appreciated.
Thanks,

Mick Chang
cha...@adenine.bchs.uh.edu

Michael Salmon

unread,
May 29, 1996, 3:00:00 AM5/29/96
to

Chang, Yu Y wrote:
>
> Hi. I am trying to set an environment variable in Tcl to pass
> it a child process. Ousterhout's and Welch's syntax of
>
> set env(VARIABLE) 'whatever'
>
> seems to only set a local tclsh variable called 'env(Variable)',
> and not to the shell environment $VARIABLE. Are there quoting
> mechanism syntax that I need to include to make the passing of
> the environment variables successful?

If you want to set an enviroment variable in your parent shell forget it. You can only affect
the environments of those programs that you run, and only before you run them.

% eos93 ~ 84 > tclsh
% set env(FOO) BAR
BAR
% exec sh -c "echo \$FOO"
BAR
%

If you want to affect your parent then the best you can do is to print a string that your
shell can eval.

--
© 1995,1996 Michael Salmon
All opinions expressed in this article remain the property of
Michael Salmon. Permission is hereby granted for use in
followup articles, FAQ's and digests.

Ray Calande

unread,
May 29, 1996, 3:00:00 AM5/29/96
to

bio...@rosie.uh.edu (Chang, Yu Y) wrote:

yyc > Hi. I am trying to set an environment variable in Tcl to pass
yyc > it a child process. Ousterhout's and Welch's syntax of
yyc > set env(VARIABLE) 'whatever'
yyc > seems to only set a local tclsh variable called 'env(Variable)',
yyc > and not to the shell environment $VARIABLE.

Although your syntax seems correct I would try double quotes. I also
question how you known that the $VARIABLE is not being passed to the
child process. You might try the following simple experiment:

set env(VARIABLE) 'whatever' ;
exec show_env.sh ;

in the file "show_env.sh"
#! /bin/sh
echo $VARIABLE > test_file.txt

After running the Tcl script look at the contents of the "test_file.txt"
file. It should contain the $VARIABLE string.

Chang, Yu Y

unread,
May 29, 1996, 3:00:00 AM5/29/96
to

Hi. I misworded my previous post. Below is the correct post.

I am trying to set an environment variable in

a child process created by a TCL process.

Ousterhout's and Welch's syntax of

set env(VARIABLE) 'whatever'

seems to only set a local tclsh variable called 'env(Variable)',

and not to the shell environment $VARIABLE. Are there quoting
mechanism syntax that I need to include to make the passing of
the environment variables successful?

Roger E. Critchlow Jr.

unread,
May 30, 1996, 3:00:00 AM5/30/96
to

Michael Salmon writes:
Chang, Yu Y wrote:
>
> Hi. I am trying to set an environment variable in Tcl to pass
> it a child process. Ousterhout's and Welch's syntax of

>
> set env(VARIABLE) 'whatever'
>
> seems to only set a local tclsh variable called 'env(Variable)',
> and not to the shell environment $VARIABLE. Are there quoting
> mechanism syntax that I need to include to make the passing of
> the environment variables successful?

If you want to set an enviroment variable in your parent shell forget it. You can only affect


the environments of those programs that you run, and only before you run them.

% eos93 ~ 84 > tclsh
% set env(FOO) BAR
BAR
% exec sh -c "echo \$FOO"
BAR
%

If you want to affect your parent then the best you can do is to print a string that your
shell can eval.

More likely, you're trying to set env(VARIABLE) inside a proc without
declaring env as a global. For instance, this echoes FOO:

proc test {} {
global env;
set env(VARIABLE) FOO
exec sh -c {echo $VARIABLE}
}

-- rec --

Hume Smith

unread,
Jun 1, 1996, 3:00:00 AM6/1/96
to

Michael Salmon <Michael...@eos.ericsson.se> writes:
> Chang, Yu Y wrote:

> > Hi. I am trying to set an environment variable in Tcl to pass
> > it a child process.

> If you want to set an enviroment variable in your parent shell forget it. You can only affect


> the environments of those programs that you run, and only before you run them.

i assume he's calling the same thing "child" that we do.

my 2¢ on the matter: i'd guess he's soing the set in a
proc body, and has forgotten his global.


Andrew Beckett

unread,
Jun 4, 1996, 3:00:00 AM6/4/96
to Chang, Yu Y

This should work. However, if you are doing this
inside a proc, you must remember to declare env as global.

i.e.

global env

set env(VARIABLE) whatever
exec env

should print out the environment variables, containing
$VARIABLE.

Cheers,

Andrew.

Chang, Yu Y wrote:
>
> Hi. I misworded my previous post. Below is the correct post.
>

> I am trying to set an environment variable in

> a child process created by a TCL process.


> Ousterhout's and Welch's syntax of
>
> set env(VARIABLE) 'whatever'
>
> seems to only set a local tclsh variable called 'env(Variable)',
> and not to the shell environment $VARIABLE. Are there quoting
> mechanism syntax that I need to include to make the passing of
> the environment variables successful?

> Any help is appreciated.
> Thanks,
>
> Mick Chang
> cha...@adenine.bchs.uh.edu

--
*************************************************************
* Andrew Beckett * Tel: +44 1344 360333 *
* Senior Applications Engineer * Fax: +44 1344 360324 *
* Cadence Design Systems Ltd * Email: and...@cadence.com *
* Bagshot Road * *
* Bracknell. RG12 3PH * *
*************************************************************

0 new messages