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


Groups > comp.lang.python > #20593 > unrolled thread

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

Started bySherjilOzair <sherjilozair@gmail.com>
First post2012-02-18 10:58 -0800
Last post2012-02-21 11:15 +0200
Articles 16 — 10 participants

Back to article view | Back to comp.lang.python


Contents

  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

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

FromSherjilOzair <sherjilozair@gmail.com>
Date2012-02-18 10:58 -0800
SubjectPython as a default shell, replacement of bash, sh, cmd ?
Message-ID<24942665.31.1329591482717.JavaMail.geo-discussion-forums@pbux2>
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?

[toc] | [next] | [standalone]


#20594

FromJabba Laci <jabba.laci@gmail.com>
Date2012-02-18 20:21 +0100
Message-ID<mailman.5945.1329592942.27778.python-list@python.org>
In reply to#20593
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 <sherjilozair@gmail.com> 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

[toc] | [prev] | [next] | [standalone]


#20595

From88888 Dihedral <dihedral88888@googlemail.com>
Date2012-02-18 13:46 -0800
Message-ID<mailman.5946.1329601587.27778.python-list@python.org>
In reply to#20594
在 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 <sherjilozair@gmail.com> 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. 
 

[toc] | [prev] | [next] | [standalone]


#20596

From88888 Dihedral <dihedral88888@googlemail.com>
Date2012-02-18 13:46 -0800
Message-ID<4874001.114.1329601576682.JavaMail.geo-discussion-forums@pbcr5>
In reply to#20594
在 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 <sherjilozair@gmail.com> 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. 
 

[toc] | [prev] | [next] | [standalone]


#20604

FromBryan <bryanjugglercryptographer@yahoo.com>
Date2012-02-18 20:05 -0800
Message-ID<12644c63-c7df-49fb-b3e9-16029057cee3@sk8g2000pbc.googlegroups.com>
In reply to#20593
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.

[toc] | [prev] | [next] | [standalone]


#20608

FromSherjilOzair <sherjilozair@gmail.com>
Date2012-02-19 00:18 -0800
Message-ID<6736331.2480.1329639496391.JavaMail.geo-discussion-forums@pbbox6>
In reply to#20604
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 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.

[toc] | [prev] | [next] | [standalone]


#20612

FromTerry Reedy <tjreedy@udel.edu>
Date2012-02-19 13:28 -0500
Message-ID<mailman.5953.1329676141.27778.python-list@python.org>
In reply to#20608
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

[toc] | [prev] | [next] | [standalone]


#20609

FromSherjilOzair <sherjilozair@gmail.com>
Date2012-02-19 00:16 -0800
Message-ID<20872530.6.1329639403963.JavaMail.geo-discussion-forums@pbt8>
In reply to#20604
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 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.

[toc] | [prev] | [next] | [standalone]


#20610

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-02-19 08:49 +0000
Message-ID<4f40b7b5$0$29986$c3e8da3$5496439d@news.astraweb.com>
In reply to#20609
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

[toc] | [prev] | [next] | [standalone]


#20671

From"Kyle T. Jones" <onexpadREMOVE@EVOMERyahoodotyouknow.com>
Date2012-02-21 20:28 -0600
Message-ID<ji1jsf$hrm$1@dont-email.me>
In reply to#20609
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.

[toc] | [prev] | [next] | [standalone]


#20682

FromGrant Edwards <invalid@invalid.invalid>
Date2012-02-22 15:31 +0000
Message-ID<ji31nu$btj$1@reader1.panix.com>
In reply to#20671
On 2012-02-22, Kyle T. Jones <onexpadREMOVE@EVOMERyahoodotyouknow.com> 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!!

[toc] | [prev] | [next] | [standalone]


#20697

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-02-22 22:15 +0000
Message-ID<4f45691a$0$29986$c3e8da3$5496439d@news.astraweb.com>
In reply to#20682
On Wed, 22 Feb 2012 15:31:10 +0000, Grant Edwards wrote:

> On 2012-02-22, Kyle T. Jones <onexpadREMOVE@EVOMERyahoodotyouknow.com>
> 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

[toc] | [prev] | [next] | [standalone]


#20615

FromMichael Torrie <torriem@gmail.com>
Date2012-02-19 17:23 -0700
Message-ID<mailman.0.1329697429.3037.python-list@python.org>
In reply to#20593
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.

[toc] | [prev] | [next] | [standalone]


#20616

From88888 Dihedral <dihedral88888@googlemail.com>
Date2012-02-19 22:15 -0800
Message-ID<15520563.12.1329718544660.JavaMail.geo-discussion-forums@pbnv3>
In reply to#20615
在 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.  

[toc] | [prev] | [next] | [standalone]


#20617

From88888 Dihedral <dihedral88888@googlemail.com>
Date2012-02-19 22:15 -0800
Message-ID<mailman.3.1329718553.3037.python-list@python.org>
In reply to#20615
在 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.  

[toc] | [prev] | [next] | [standalone]


#20662

FromSerhiy Storchaka <storchaka@gmail.com>
Date2012-02-21 11:15 +0200
Message-ID<mailman.28.1329815748.3037.python-list@python.org>
In reply to#20593
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/).

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web