os.putenv ?

Stuart Bishop zen at shangri-la.dropbear.id.au
Fri Mar 28 13:37:41 CET 2003


On Friday, March 28, 2003, at 06:54  PM, Jacek Generowicz wrote:

> sik0fewl <xxdigitalhellxx at hotmail.com> writes:
>
>>> Set up the environment for a user who is about to be running lots
>>> of Python scripts ... without having to write a shell script for
>>> each flavour of UNIX shell under the sun ... so trying it in
>>> Python seemed the natural way.
>>
>> I don't think that's necessary. Write a bourne shell script, I'm
>> pretty sure every* system comes with it.

> Great. Now ... what if the user uses tcsh ..

% exec env GRR="This is a late parrot." $SHELL
% echo $GRR
This is a late parrot.

Or you can use the script-generated shell commands approach, although
this is overkill unless you are trying to do something more complicated
(such as insert elements into PATH or CLASSPATH etc).

#!python
import os
m = { 'GRR': 'This is a late parrot.' }
if os.environ['SHELL'].endswith('csh'):
     for k,v in m.items():
         print "setenv %s '%s'" % (k,v)
else:
     for k,v in m.items():
         print "export %s='%s'" % (k,v)


% eval `python_env`
% echo $GRR
This is a late parrot.

-- 
Stuart Bishop <zen at shangri-la.dropbear.id.au>
http://shangri-la.dropbear.id.au/






More information about the Python-list mailing list