programmatically manipulation environment variables of the calling shell
Maxim Veksler
hq4ever at gmail.com
Mon Mar 12 07:29:03 EDT 2007
On 3/12/07, Tommy Nordgren <tommy.nordgren at comhem.se> wrote:
>
> On 12 mar 2007, at 11.33, Maxim Veksler wrote:
>
> > Hello list,
> >
> > I'm trying to write a python script that would allow me to manipulate
> > shell variables of the calling shell. I'm trying to write some logic
> > that would know to add LD_LIBRARY_PATH to the users environment.
> >
> > In bash this is done with "export", can I do this with python? (If at
> > all possible because python is actually a sub process of bash).
> >
> > Thank you,
> > Maxim.
> This is not possible to do directly.
> There is however a possibility to solve this problem under special
> circumstances.
> 1. Your python (/perl/shell/etc) script must write the wanted
> environment
> variables to standard out, as key-value pairs with a suitable separator.
> 2. The invoking shell must agree with your script as to what
> separator is used.
> 3. In the calling shell do myshellvars=`your_python_script`;
> 4. Now the calling shell can parse the variable myshellvars to set
> up the environment.
Yes, thats exactly what I was set to do.
<<< bash
for export_val in $(python env_variables_maxim.py); do export $export_val; done
>>>
<<< python (env_variables_maxim.py)
print 'FOO=123 BAR=/home/src:$BAR PATH=/nfs/bin'
>>>
Thank you.
> ------
> What is a woman that you forsake her, and the hearth fire and the
> home acre,
> to go with the old grey Widow Maker. --Kipling, harp song of the
> Dane women
> Tommy Nordgren
> tommy.nordgren at comhem.se
>
>
>
>
--
Cheers,
Maxim Veksler
"Free as in Freedom" - Do u GNU ?
More information about the Python-list
mailing list