python: can you update the current shell from python?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
yes... python is can operate at the same level as any other terminal process, here's a very simple example of executing system commands (no capture of results other than exit code):
iret = os.system("ls -al")
if iret != 0:
print "Error - child terminated with signal ", iret
yes, that runs a system command, but it does nothing to my current shell.
os.system("setenv FOO bar")
will set an env var (in tcsh) for the time that python is running, but as soon as the python script terminates, so does that env var. I'm looking for a way to keep that env var around, or, more specifically, to keep a complete alias around.
Can I update the current shell with a python script?
I can run scripts from within python, but I'm not sure how to make python's changes stick in the current shell.
Sure arrange to source the output of a Python script then the Python script can output the text to set an environment variable (or three), and that will be sourced by the outer shell so changing the environment for subsequent commands.
well i'm having trouble with lot! I can't seem to do 'export LFS=/mnt/lfs', use declare or setenv (setenv is giving errors), even straight from shell? It's 6.10am an i'm off to bed, i'll look again tomorrow>>