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
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.
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.
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?
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 --
> > 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.
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 * *
*************************************************************