Python as a default shell, replacement of bash, sh, cmd ?

Discussion in 'Python' started by SherjilOzair, Feb 18, 2012.

  1. SherjilOzair

    SherjilOzair Guest

    Has it been considered to add shell features to python, such that it can be used as a default shell, as a replacement for bash, etc.

    I'm sure everyone would agree that doing this would make the terminal very powerful.

    What are your views on this?
     
    SherjilOzair, Feb 18, 2012
    #1
    1. Advertising

  2. SherjilOzair

    Jabba Laci Guest

    Have a look at IPython (http://ipython.org/). It can interact with the
    normal shell very well.

    Laszlo

    On Sat, Feb 18, 2012 at 19:58, SherjilOzair <> wrote:
    > Has it been considered to add shell features to python, such that it can be used as a default shell, as a replacement for bash, etc.
    >
    > I'm sure everyone would agree that doing this would make the terminal very powerful.
    >
    > What are your views on this?
    > --
    > http://mail.python.org/mailman/listinfo/python-list
     
    Jabba Laci, Feb 18, 2012
    #2
    1. Advertising

  3. 在 2012å¹´2月19日星期日UTC+8上åˆ3æ—¶21分53秒,Jabba Laci写é“:
    > Have a look at IPython (http://ipython.org/). It can interact with the
    > normal shell very well.
    >
    > Laszlo
    >
    > On Sat, Feb 18, 2012 at 19:58, SherjilOzair <> wrote:
    > > Has it been considered to add shell features to python, such that it can be used as a default shell, as a replacement for bash, etc.
    > >
    > > I'm sure everyone would agree that doing this would make the terminal very powerful.
    > >
    > > What are your views on this?
    > > --
    > > http://mail.python.org/mailman/listinfo/python-list


    Yeh, python could be used as a better shell in a text
    terminal box and with another text editor in
    another box to write scripts in developement.

    Also this is easy to test scripts found in the web by copy and paste.
     
    88888 Dihedral, Feb 18, 2012
    #3
  4. SherjilOzair

    Bryan Guest

    SherjilOzair wrote:
    > Has it been considered to add shell features
    > to python, such that it can be used as a
    > default shell, as a replacement for bash, etc.


    I think yes, but rather than become a shell, Python makes easy
    programming a shell that can execute Python code. The tendency has
    been to excel as a scripting language, and prefer to add extra
    features to the standard library.

    To start, look at the built-in functions eval() and (raw_)input; and
    the library modules: subprocess, os and os.path, glob and re, shutil,
    and code.

    > I'm sure everyone would agree that doing this
    > would make the terminal very powerful.


    'Cept of course that they already are.
     
    Bryan, Feb 19, 2012
    #4
  5. SherjilOzair

    SherjilOzair Guest

    Well, if not modify python itself, I was thinking of making another shell, which borrows a lot from python, something like merging bash and python. such that I can do `cd ~/Desktop/dev` and `for i in open('file.txt'): print i` at the some shell. This I think would be VERY useful.

    IPyhton is very good, but after all, it is just an advanced interpreter, not a default shell. I don't want this to run on top of bash or sh. But it should run on its own, at shell level.

    Bash and sh, according to me, have very ugly syntaxes and the general user does not even use those. Python put on the shell would be adhering to python's vision, i.e. bringing programming to the masses.
    The general user, who earlier could not do batch operations, and had to buysoftware and such for all that, could now write his open simple python script and run it in his shell that would do as he wants.

    Python on the shell could effectively remove learning grep, awk, sed, bash and the various unix utilities.
    Don't take me wrong. Those are awesome tools, and I use them. But the awesomeness is not experienced by the general UNIX user on mac or linux. Python could do that.

    We all know how great a programming language python is. Imagine being able to control your computer with such an elegant language. Imagine that I import some speech recognition utility on the terminal shell, and voila, I'm speaking to the computer and it is doing stuff on the terminal for me.

    Shell would give python raw power! And Python would manage it well.
     
    SherjilOzair, Feb 19, 2012
    #5
  6. SherjilOzair

    SherjilOzair Guest

    Well, if not modify python itself, I was thinking of making another shell, which borrows a lot from python, something like merging bash and python. such that I can do `cd ~/Desktop/dev` and `for i in open('file.txt'): print i` at the some shell. This I think would be VERY useful.

    IPyhton is very good, but after all, it is just an advanced interpreter, not a default shell. I don't want this to run on top of bash or sh. But it should run on its own, at shell level.

    Bash and sh, according to me, have very ugly syntaxes and the general user does not even use those. Python put on the shell would be adhering to python's vision, i.e. bringing programming to the masses.
    The general user, who earlier could not do batch operations, and had to buysoftware and such for all that, could now write his open simple python script and run it in his shell that would do as he wants.

    Python on the shell could effectively remove learning grep, awk, sed, bash and the various unix utilities.
    Don't take me wrong. Those are awesome tools, and I use them. But the awesomeness is not experienced by the general UNIX user on mac or linux. Python could do that.

    We all know how great a programming language python is. Imagine being able to control your computer with such an elegant language. Imagine that I import some speech recognition utility on the terminal shell, and voila, I'm speaking to the computer and it is doing stuff on the terminal for me.

    Shell would give python raw power! And Python would manage it well.
     
    SherjilOzair, Feb 19, 2012
    #6
  7. On Sun, 19 Feb 2012 00:16:43 -0800, SherjilOzair wrote:

    > Well, if not modify python itself, I was thinking of making another
    > shell, which borrows a lot from python, something like merging bash and
    > python. such that I can do `cd ~/Desktop/dev` and `for i in
    > open('file.txt'): print i` at the some shell. This I think would be VERY
    > useful.
    >
    > IPyhton is very good, but after all, it is just an advanced interpreter,
    > not a default shell. I don't want this to run on top of bash or sh. But
    > it should run on its own, at shell level.


    That's up to your operating system. If your OS lets you choose a shell,
    tell it to use IPython. IPython already supports being used as the system
    shell:

    http://ipython.org/ipython-doc/dev/interactive/shell.html
    http://transneptune.net/2009/06/16/ipython-as-your-default-shell/

    If your OS doesn't support choosing a shell, you can't use anything but
    the built-in shell regardless of what Python does.

    Either way, this is not a Python problem to solve. It is an OS issue.


    --
    Steven
     
    Steven D'Aprano, Feb 19, 2012
    #7
  8. SherjilOzair

    Terry Reedy Guest

    On 2/19/2012 3:18 AM, SherjilOzair wrote:
    > Well, if not modify python itself, I was thinking of making another
    > shell, which borrows a lot from python, something like merging bash
    > and python. such that I can do `cd ~/Desktop/dev` and `for i in


    'cd xxx' cannot work because that is not python syntax. "cd('xxx')"
    could. Right now, one can import os and do shell stuff, but not so
    convinient for interactive use. 'os.chdir' is not so convenient as 'cd'.
    Two possible options, either of which might exist on PyPI:

    1. a shell module used as 'from bashshell import *' which would have
    functions closely mimicking, in this example, bash

    2. a shell module used as 'from bashshell import bash; bash()' which
    would invoke an sub-interactive mode like help() that would allow 'cd
    xxx' and similar syntax, which still affecting the global environment.
    The latter would trade the inconvenience of '()'s for the inconvenience
    of entering and exiting a special submode.

    I have not used IPYthon so I have no idea how close it gets to either of
    these.

    --
    Terry Jan Reedy
     
    Terry Reedy, Feb 19, 2012
    #8
  9. On 02/18/2012 11:58 AM, SherjilOzair wrote:
    > Has it been considered to add shell features to python, such that it
    > can be used as a default shell, as a replacement for bash, etc.
    >
    > I'm sure everyone would agree that doing this would make the terminal
    > very powerful.
    >
    > What are your views on this?


    I use python for system programming all the time, in place of bash.
    However Python is not designed as shell language, just as Bash is not
    really designed for the type of application development that Python is.

    Bash works by giving you a view of the file system as your primary way
    of interacting with it as a shell. This is ideal because usually you
    want to manipulate files and processes (that's just what you do on a
    command line shell normally). Python doesn't work on that level. Like
    other langueages like php, you can manipulate files and processes
    through standard library calls. Frankly doing:

    cd ~/blah

    is much faster and more convenient in an interactive shell than:

    import os
    os.chdir(os.getenv("HOME") + "/blah")

    Also bash is designed to start and control processes:

    ls *.txt | wc -l
    or
    someprocess | grep something 2>&1 > /tmp/somefile.txt

    In python there is no direct correlation to these things, and in fact
    Python has different ways of doing that kind of thing (better for some
    things) if you want to write scripts (for example,
    http://www.dabeaz.com/generators/)

    My own experience has shown me that Python is a very capable
    systems-programming language, but that traditional shells are there for
    a reason. And if I need to script something, I usually go to Bash first
    because it's simpler and easier, at least for very small tasks. Once
    the bash script gets to be 100 lines or more, I switch to python. Then
    I use some modules I wrote myself to make subprocess.Popen a little
    simpler. Another library that I heard about on this list, called
    extproc, also seems to be similarly great for doing this.

    There have been attempts over the years to bring access to files and
    processes into python and still be pythonic, but they are all awkward.
    For example, this sort of syntax using dynamic attributes:

    shell.wc(shell.ls('/tmp/*.txt'), "-l")
    or
    shell.ls('/tmp/*.txt').pipe(shell.wc())

    But it turns out that coming up with a python-compatible syntax is
    pretty hard, especially when it comes to pipes (don't forget standard
    err!) Besides all this, it's just plain awkward and unnecessary.
     
    Michael Torrie, Feb 20, 2012
    #9
  10. 在 2012å¹´2月20日星期一UTC+8上åˆ8æ—¶23分33秒,Michael Torrie写é“:
    > On 02/18/2012 11:58 AM, SherjilOzair wrote:
    > > Has it been considered to add shell features to python, such that it
    > > can be used as a default shell, as a replacement for bash, etc.
    > >
    > > I'm sure everyone would agree that doing this would make the terminal
    > > very powerful.
    > >
    > > What are your views on this?

    >
    > I use python for system programming all the time, in place of bash.
    > However Python is not designed as shell language, just as Bash is not
    > really designed for the type of application development that Python is.
    >

    To use Python as a shell with customized scripts is feasiable for those hose have to work on different OS enviroments from time to time. This is a handy approach to ease the user the burden to memorize
    different commands of different OS environments.

    Of course, this might add some overheads in executing some operations.

    Nowadays attracting more people especially noices to use linux is the way to keep unix programming alive in the future.
     
    88888 Dihedral, Feb 20, 2012
    #10
  11. 18.02.12 20:58, SherjilOzair напиÑав(ла):
    > Has it been considered to add shell features to python, such that it can be used as a default shell, as a replacement for bash, etc.
    >
    > I'm sure everyone would agree that doing this would make the terminal very powerful.
    >
    > What are your views on this?


    Look at Hotwire (http://code.google.com/p/hotwire-shell/).
     
    Serhiy Storchaka, Feb 21, 2012
    #11
  12. On 2/19/12 2:16 AM, SherjilOzair wrote:
    > Well, if not modify python itself, I was thinking of making another shell, which borrows a lot from python, something like merging bash and python. such that I can do `cd ~/Desktop/dev` and `for i in open('file.txt'): print i` at the some shell. This I think would be VERY useful.
    >


    That's an awful lot of key mashing just to replace 'cat file.txt'

    for i in big small upper lower ; do for j in conf bin log ; do chmod
    2755 /home/me/$i/$j ; done ; done

    cat data.log | grep Error | awk -F, '{print $5, $1, $2,}' | sort

    ??

    I believe your solution seeks a problem. I also believe a tool that
    seeks to be all things generally does none of them particularly well.

    Cheers.

    > IPyhton is very good, but after all, it is just an advanced interpreter, not a default shell. I don't want this to run on top of bash or sh. But it should run on its own, at shell level.
    >
    > Bash and sh, according to me, have very ugly syntaxes and the general user does not even use those. Python put on the shell would be adhering to python's vision, i.e. bringing programming to the masses.
    > The general user, who earlier could not do batch operations, and had to buy software and such for all that, could now write his open simple python script and run it in his shell that would do as he wants.
    >
    > Python on the shell could effectively remove learning grep, awk, sed, bash and the various unix utilities.
    > Don't take me wrong. Those are awesome tools, and I use them. But the awesomeness is not experienced by the general UNIX user on mac or linux. Python could do that.
    >
    > We all know how great a programming language python is. Imagine being able to control your computer with such an elegant language. Imagine that I import some speech recognition utility on the terminal shell, and voila, I'm speaking to the computer and it is doing stuff on the terminal for me.
    >
    > Shell would give python raw power! And Python would manage it well.
     
    Kyle T. Jones, Feb 22, 2012
    #12
  13. On 2012-02-22, Kyle T. Jones <> wrote:
    > On 2/19/12 2:16 AM, SherjilOzair wrote:
    >> Well, if not modify python itself, I was thinking of making another shell, which borrows a lot from python, something like merging bash and python. such that I can do `cd ~/Desktop/dev` and `for i in open('file.txt'): print i` at the some shell. This I think would be VERY useful.
    >>

    >
    > That's an awful lot of key mashing just to replace 'cat file.txt'


    No kidding. And how much python would it take to do "less file.txt"?

    > for i in big small upper lower ; do for j in conf bin log ; do chmod
    > 2755 /home/me/$i/$j ; done ; done


    chmod 2755 /home/me/{big,small,upper,lower}/{conf,bin,log}

    > cat data.log | grep Error | awk -F, '{print $5, $1, $2,}' | sort


    awk -F, '/Error/ {print $5, $1, $2}' data.log | sort

    ;)

    Any decent modern shell (e.g. Bash) is a stunningly powerful
    environment aimed at solving a certain sort of problems in a certain
    way. Python is aimed at solving a more general set of problems in an
    entirely different way.

    Yes, you can drive a nail with a screwdriver if you try hard enough
    long enough, but it's still a bad idea.

    --
    Grant Edwards grant.b.edwards Yow! FOOLED you! Absorb
    at EGO SHATTERING impulse
    gmail.com rays, polyester poltroon!!
     
    Grant Edwards, Feb 22, 2012
    #13
  14. On Wed, 22 Feb 2012 15:31:10 +0000, Grant Edwards wrote:

    > On 2012-02-22, Kyle T. Jones <>
    > wrote:
    >> On 2/19/12 2:16 AM, SherjilOzair wrote:
    >>> Well, if not modify python itself, I was thinking of making another
    >>> shell, which borrows a lot from python, something like merging bash
    >>> and python. such that I can do `cd ~/Desktop/dev` and `for i in
    >>> open('file.txt'): print i` at the some shell. This I think would be
    >>> VERY useful.
    >>>
    >>>

    >> That's an awful lot of key mashing just to replace 'cat file.txt'

    >
    > No kidding. And how much python would it take to do "less file.txt"?


    A lot less than the amount of C it takes to do "less file.txt".

    I trust you don't imagine that a Python shell would require the user to
    re-implement "less" using nothing but built-ins each time they needed it.
    There would be a pre-made "less" replacement (which may even be a wrapper
    around the system "less") never more than one import away. You can
    already do something very close to this right now:

    from pydoc import pager
    pager(open("file.txt").read())

    How much effort would it take to turn pydoc.pager into a full replacement
    for "less"? I don't know, but it would only need to be done ONCE.

    This is not a theoretical argument. IPython already does this. It not
    only gives you full access to all your shell commands, plus more, but it
    let's you use something very close to shell syntax to do it.

    http://ipython.org/ipython-doc/dev/interactive/shell.html

    The advantage of a Python shell like IPython is not for trivial shell
    commands like "less file.txt". I can think of at least four reasons why
    you might consider a Python shell would be awesome:

    "I know Python, and I don't know bash. What do I care if it takes five
    lines to perform a task in Python, vs one line in bash, if it would take
    me half an hour of reading man pages and seven attempts to get the bash
    version right?"

    "I'm fed up to the back teeth of the shell's cryptic syntax, magic global
    variables and especially its arcane string quoting rules."

    "I'm sick and tired of having to parse human-readable presentation text
    to get the answers I want. I want an environment where the tools don't
    mix content and presentation by default."

    "My OS has a shell which sucks and blows at the same time. I want
    something better."

    So basically, there exists a niche for Python as a shell, and thanks to
    the time machine, there already exists a powerful Python shell ready to
    fill that niche.


    --
    Steven
     
    Steven D'Aprano, Feb 22, 2012
    #14
    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,302
    William Park
    Jul 14, 2005
  2. Achim Domma (Procoders)

    read input for cmd.Cmd from file

    Achim Domma (Procoders), Jun 3, 2005, in forum: Python
    Replies:
    2
    Views:
    8,081
    Peter Otten
    Jun 3, 2005
  3. edwithad

    Bash shell to Python shell?

    edwithad, Sep 28, 2009, in forum: Python
    Replies:
    4
    Views:
    1,747
  4. Jean-Michel Pichavant

    python cmd.Cmd auto complete feature

    Jean-Michel Pichavant, Mar 8, 2011, in forum: Python
    Replies:
    0
    Views:
    319
    Jean-Michel Pichavant
    Mar 8, 2011
  5. Jean-Michel Pichavant

    Re: python cmd.Cmd auto complete feature

    Jean-Michel Pichavant, Mar 9, 2011, in forum: Python
    Replies:
    0
    Views:
    465
    Jean-Michel Pichavant
    Mar 9, 2011
Loading...

Share This Page