Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #20615

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

Date 2012-02-19 17:23 -0700
From Michael Torrie <torriem@gmail.com>
Subject Re: Python as a default shell, replacement of bash, sh, cmd ?
References <24942665.31.1329591482717.JavaMail.geo-discussion-forums@pbux2>
Newsgroups comp.lang.python
Message-ID <mailman.0.1329697429.3037.python-list@python.org> (permalink)

Show all headers | View raw


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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python as a default shell, replacement of bash, sh, cmd ? SherjilOzair <sherjilozair@gmail.com> - 2012-02-18 10:58 -0800
  Re: Python as a default shell, replacement of bash, sh, cmd ? Jabba Laci <jabba.laci@gmail.com> - 2012-02-18 20:21 +0100
    Re: Python as a default shell, replacement of bash, sh, cmd ? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-18 13:46 -0800
    Re: Python as a default shell, replacement of bash, sh, cmd ? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-18 13:46 -0800
  Re: Python as a default shell, replacement of bash, sh, cmd ? Bryan <bryanjugglercryptographer@yahoo.com> - 2012-02-18 20:05 -0800
    Re: Python as a default shell, replacement of bash, sh, cmd ? SherjilOzair <sherjilozair@gmail.com> - 2012-02-19 00:18 -0800
      Re: Python as a default shell, replacement of bash, sh, cmd ? Terry Reedy <tjreedy@udel.edu> - 2012-02-19 13:28 -0500
    Re: Python as a default shell, replacement of bash, sh, cmd ? SherjilOzair <sherjilozair@gmail.com> - 2012-02-19 00:16 -0800
      Re: Python as a default shell, replacement of bash, sh, cmd ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-19 08:49 +0000
      Re: Python as a default shell, replacement of bash, sh, cmd ? "Kyle T. Jones" <onexpadREMOVE@EVOMERyahoodotyouknow.com> - 2012-02-21 20:28 -0600
        Re: Python as a default shell, replacement of bash, sh, cmd ? Grant Edwards <invalid@invalid.invalid> - 2012-02-22 15:31 +0000
          Re: Python as a default shell, replacement of bash, sh, cmd ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-22 22:15 +0000
  Re: Python as a default shell, replacement of bash, sh, cmd ? Michael Torrie <torriem@gmail.com> - 2012-02-19 17:23 -0700
    Re: Python as a default shell, replacement of bash, sh, cmd ? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-19 22:15 -0800
    Re: Python as a default shell, replacement of bash, sh, cmd ? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-02-19 22:15 -0800
  Re: Python as a default shell, replacement of bash, sh, cmd ? Serhiy Storchaka <storchaka@gmail.com> - 2012-02-21 11:15 +0200

csiph-web