Bash shell to Python shell?

Discussion in 'Python' started by edwithad, Sep 28, 2009.

  1. edwithad

    edwithad Guest

    I am sure you have not read a question this basic in some time, but I
    am curious. Using Linux I open a terminal window and type: python.

    Does Bash Shell go away and to become a Python Shell, or is it still a
    Bash Shell with Python running inside? Thanks in advance.
     
    edwithad, Sep 28, 2009
    #1
    1. Advertising

  2. edwithad

    Chris Rebert Guest

    On Sun, Sep 27, 2009 at 8:13 PM, edwithad <> wrote:
    > I am sure you have not read a question this basic in some time, but I am
    > curious. Using Linux I open a terminal window and type: python.
    >
    > Does Bash Shell go away and to become a Python Shell, or is it still a Bash
    > Shell with Python running inside? Thanks in advance.


    The latter. Press Ctrl+D or enter exit() or quit() to exit Python and
    return to bash.

    Cheers,
    Chris
    --
    http://blog.rebertia.com
     
    Chris Rebert, Sep 28, 2009
    #2
    1. Advertising

  3. edwithad

    Ned Deily Guest

    In article <2009092721134550073-edwithad@hotmailcom>,
    edwithad <> wrote:
    > I am sure you have not read a question this basic in some time, but I
    > am curious. Using Linux I open a terminal window and type: python.
    >
    > Does Bash Shell go away and to become a Python Shell, or is it still a
    > Bash Shell with Python running inside? Thanks in advance.


    See for youself:

    $ ps
    PID TTY TIME CMD
    17478 pts/0 00:00:00 bash
    17571 pts/0 00:00:00 ps

    $ python
    Python 2.5.4 (r254:67916, Feb 17 2009, 20:16:45)
    [GCC 4.3.3] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import os
    >>> os.system('ps')

    PID TTY TIME CMD
    17478 pts/0 00:00:00 bash
    17572 pts/0 00:00:00 python
    17573 pts/0 00:00:00 sh
    17574 pts/0 00:00:00 ps
    0
    >>>


    So you can see that the top-level shell (process id 17478) starts new
    child processes to run other programs (17571 for the ps in the first
    example, 17572 for python in the second), just as the python os.system
    function starts a new shell (17573, a default /bin/sh) to process the
    'ps' argument string passed to it and that shell starts another process
    (17574) to run 'ps'.

    For a more detailed explanation of what's going on, see, for example:

    http://tldp.org/HOWTO/Unix-and-Internet-Fundamentals-HOWTO/running-progra
    ms.html

    --
    Ned Deily,
     
    Ned Deily, Sep 28, 2009
    #3
  4. On 2009-09-28, Chris Rebert <> wrote:
    > On Sun, Sep 27, 2009 at 8:13 PM, edwithad <> wrote:
    >> I am sure you have not read a question this basic in some time, but I am
    >> curious. Using Linux I open a terminal window and type: python.
    >>
    >> Does Bash Shell go away and to become a Python Shell, or is it still a Bash
    >> Shell with Python running inside? Thanks in advance.

    >
    > The latter. Press Ctrl+D or enter exit() or quit() to exit Python and
    > return to bash.


    Bash doesn't really "go away". It's still there, it just hands
    over the terminal to the python interpreter and then sits and
    waits for the python interpreter to exit. At that point the
    Bash shell (the same one as before) resumes.

    --
    Grant
     
    Grant Edwards, Sep 28, 2009
    #4
  5. edwithad

    Guest

    Chris Rebert <> wrote:
    > On Sun, Sep 27, 2009 at 8:13 PM, edwithad <> wrote:
    >> I am sure you have not read a question this basic in some time, but I am
    >> curious. Using Linux I open a terminal window and type: python.
    >>
    >> Does Bash Shell go away and to become a Python Shell, or is it still a Bash
    >> Shell with Python running inside? Thanks in advance.

    >
    > The latter. Press Ctrl+D or enter exit() or quit() to exit Python and
    > return to bash.
    >


    Or, if you prefer the bash shell to be replaced with the python, just type:
    exec python

    --
    -----------------------------------------------------------
    | Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
    | __..--^^^--..__ garabik @ kassiopeia.juls.savba.sk |
    -----------------------------------------------------------
    Antivirus alert: file .signature infected by signature virus.
    Hi! I'm a signature virus! Copy me into your signature file to help me spread!
     
    , Sep 28, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William Park

    (patch for Bash) GTK+2 + Bash

    William Park, Jul 11, 2005, in forum: XML
    Replies:
    3
    Views:
    2,320
    William Park
    Jul 14, 2005
  2. John Salerno

    using python at the bash shell?

    John Salerno, Aug 8, 2006, in forum: Python
    Replies:
    16
    Views:
    1,812
    Marc 'BlackJack' Rintsch
    Aug 16, 2006
  3. Gros Bedo
    Replies:
    2
    Views:
    1,354
    Piet van Oostrum
    Jul 10, 2008
  4. Gros Bedo
    Replies:
    1
    Views:
    685
    Piet van Oostrum
    Jul 10, 2008
  5. norseman
    Replies:
    0
    Views:
    580
    norseman
    Jul 10, 2008
Loading...

Share This Page