[svlug] Adding environment variable to a shell and it's

Ian Kluft ikluft at thunder.sbay.org
Fri May 30 15:36:50 PDT 2003


>From: Roland Krause <rokrau at yahoo.com>
>Is there a way under Linux and bash/tcsh to add a environment variable
>to a shell that's running noninteractively and to propagate the
>variable to it's subprocesses? 
>
>Say that I have started a program from within KDE's windowmanager and
>that I want this program to recognize that a certain environment
>variable has been set that was not set when the user logged in.
>
>Is this possible at all? I wouldnt even mind restarting the app but it
>*must* be without starting a terminal/shell/konsole etc. 

Rafael's answer of reading a configuration file is correct if you want
to be able to change the environment at any time the program is running.

If you constrain the problem to setting the environment variables when
you start the program from your GUI environment, there's a simpler solution.
You could use a "wrapper script" to set the environment variables and then
launch the program.  Just have your GUI environment run the wrapper script
instead of the program itself.

(A wrapper script is simply a shell/perl/etc script to change the
environment or possibly other actions before starting a program.)

Since I use Gnome, I don't know specific directions for KDE off the top of
my head.  But this is true of any Unix-based GUI.  Wherever you specify the
properties of the program to launch, use the wrapper script instead of the
GUI program.  The wrapper script will, of course, run the GUI program after
it sets the environment.

It may also be possible to set some simple variables on the command line
of the program, like this:
   VAR=VALUE program-name arguments ...




More information about the svlug mailing list