programmatically manipulation environment variables of the calling shell

Tommy Nordgren tommy.nordgren at comhem.se
Mon Mar 12 07:21:48 EDT 2007


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






More information about the Python-list mailing list