[Tutor] python as unix shell
Hans Nowak
hnowak@cuci.nl
Sat, 16 Oct 1999 09:07:14 +0200
On 15 Oct 99, at 14:52, Blake Winton wrote:
> > Has anyone tried having python as the login shell?
> > Tips and scripts (esp. for reading email using imap) would be much
> > appreciated.
>
> Don't.
>
> When I first started using Python, I gave it a try, but having to type
> "os.system(" in front of every command convinced me that I was insane, and
> so I switched back to zsh, like God intended. ;)
>
> Of course, I've seen reference to a PythonShell since then, which I
> haven't tried. Maybe it's time to start that up again. But evidently
> not, since I can't find the url. :P If anyone else knows where I might
> find it, please email me.
I doubt you have seen references to it (was probably another shell),
but I wrote an experimental pysh with lots of flaws. :)
In fact it just simulates a Python interpreter session, but it
accepts lines starting with an @, and passes such lines to the
system. So you can do
>>> x = "c*"
>>> @ls
(executes ls and displays output)
>>> @ls $x$
(executes 'ls c*')
Parts between $..$ will be substituted; in this case, the variable x
is taken and its contents are placed in the command.
I call it flawed because of several reasons... I wrote it in 1998,
and in the meantime a better Python interpreter class has shown up in
the standard library, if I'm not mistaken. Furthermore, there are
things to worry about like redirection, piping and other common shell
thingies. Then, most importantly, there's the problem of integration.
This pysh can execute commands and substitute a bit, but that's about
it. It would be nice if it could, for instance, work with a list of
files, and feed that list to a command rather than using literal
filenames in the command. It would be nice if commands like ls could
return a list with files besides dumping output of screen (this would
require writing all the common commands in Python, or maybe some
filter function to scan the output). It would be nice if I could
write something like
def ls(opt):
@ls $opt$
so, with the @ embedded in a function. And there's lots more to wish
for. Which makes me think I am probably not the right person to write
a serious pysh; this was a nice experiment, but not much more than
that.
Anyone wrote a better one?
--Hans Nowak (zephyrfalcon@hvision.nl)
Homepage: http://fly.to/zephyrfalcon
Python Snippets: http://tor.dhs.org/~zephyrfalcon/snippets/
The Purple Kookaburra Forum: http://www.delphi.com/kookaburra/