Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-07-2007, 09:35 AM   #1
Registered: Jun 2006
Location: Sydney
Distribution: Gentoo + Debian
Posts: 132

Rep: Reputation: 15
Source Bash variables into Python environ.

I'm looking for a way to source a bash file and get some variables defined within to appear within my python environment. Something like...

import os
env = os.environ
for i in env:
  print i + "\n",
Any ideas?
Old 05-07-2007, 10:57 AM   #2
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,397
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
In any programming language, you will have to parse the script and use the system functions (typically named something like putenv() & getenv() ) to manipulate environment variables. Any attempt to run a child shell that executes or sources the script will fail, because the child's shell is wholely independent of the parent (your program). Sorry I can't give Python-specific methods to help you.

--- rod.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
python problem - compiled from source - python -V still showing old version txm123 Linux - Newbie 1 02-15-2006 11:05 AM
variables in bash haddad Linux - General 6 09-22-2004 05:29 PM
bizarre python behavior - simple cgi variables SerfurJ Programming 2 04-14-2004 02:58 PM
Setting environ. variables before bash starts at login Bralkein Linux - Software 1 03-02-2004 05:39 PM
Using letters/strings to assign variables in python Colonel Panic Programming 0 09-14-2001 10:13 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:12 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration