Setting environment variables

David C. Fox davidcfox at post.harvard.edu
Thu Sep 18 09:13:29 EDT 2003


Erik Max Francis wrote:
> Sami Viitanen wrote:
> 
> 
>>Is there any other way to set variables than os.putenv().
>>
>>Putenv doesn't actually put any values to actual system variables..
>>
>>I'm trying to set CVSEDITOR variable automatically from script
>>so that user wouldn't have to set that him/herself. CVS can't use
>>variable
>>set with putenv().
> 
> 
> Yep, and this is a feature, at least in Unix operating systems. 
> Subshells cannot directly affect the operating environment of parent
> shells, and shouldn't try.  (One can do such things indirectly, but they
> require the cooperation of the parent shell, such as sourcing the output
> of a program, which is not an uncommon approach to the problem.)  I
> don't know if there's any way for Windows applications to affect parent
> environments, but I doubt it.
> 

In [t]csh:

   alias cvsscript "setenv CVSEDITOR `python myscript.py`"
   cvsscript

or miscellaneous variants in other shells.  Of course, you can't use 
cvsscript from within another subshell, or it will only set the variable 
in that subshell.

David






More information about the Python-list mailing list