getting env variable from bourne shell script

Thomas Guettler guettli at thomas-guettler.de
Tue Dec 21 17:04:43 CET 2004


Am Tue, 21 Dec 2004 07:51:53 -0800 schrieb biner:

> Hello,
> 
>   I have file called PARAMETRES that is used in bourne shell script to
> define variable. In order to do so I put a ". PARAMETRES" line and the
> script has acces to all the variable defined in the PARAMETRES file.

Hi,

you can run ". PARAMETERS; set" with popen. Then read stdin and
parse the lines:

The lines from stdin look like this:

ACLOCAL_PATH=/opt/gnome/share/aclocal
BASH=/bin/bash
BASH_VERSINFO=([0]="2" [1]="05b" [2]="0" [3]="1" [4]="release" [5]="i586-suse-linux")
BASH_VERSION='2.05b.0(1)-release'
COLORTERM=1
COLUMNS=143
CPU=i686
CVSROOT=:ext:tguettler at homeserver:/raid/develop
CVS_RSH=ssh
 ....

you could use '^(.*?)=(.*)$' as regex to parse each line
group(1) is the variable name group(2) the value.

 HTH,
   Thomas



-- 
Thomas Güttler, http://www.thomas-guettler.de/





More information about the Python-list mailing list