[Tutor] how to do "bash here"

Al Bogner python-tutor at ml03q3.pinguin.uni.cc
Mon Nov 17 14:50:11 EST 2003


Am Montag, 17. November 2003 07:05 schrieb Danny Yoo:

Hi Danny,

> > I try to learn python by writing working bash-scripts in python. How can
> > I do a bash-syntax like this with python:
> >
> > mysql --host=$MYSQLHOST -A --user=$MYSQLUSER --password=$MYSQLPWD
> > $MYSQLDB <<END_OF_SQLINPUT | sed '1,/^export/d' > "$FDIMPORT"
> > $MYSQLEXPORTCMDFD
> > END_OF_SQLINPUT

> Hmmm, nice shell command!  One thing you may need to fix, though, is the
> variable interpolation: passwords, too, can potentially contain spaces, so
> you need to protect those shell variables with quotes, just like how you
> protected $FDIMPORT.

Thanks for this hint, but in this case $MYSQLPWD is nothing more than a 
placeholder.


> Anyway, you may find the os.popen() command useful to simulate the "pipes"
> that the Unix shell gives us:
>
>     http://www.python.org/doc/lib/os-newstreams.html#l2h-1379
>
> And that should take care of it.  But instead of doing a literal
> translation, it might be more educational to take advantage of the tools
> that Python provides.  Otherwise, you'll probably only learn how to use
> os.popen() well.  *grin*

I would like to do my shellscrips with python as an exercise only. I don't 
want to replace my shellscripts with pythonscripts!

> If you have more questions, please feel free to ask.  Good luck to you!

Thanks a lot! The reaseon why I came to python, is to build a mysql-frontend 
with a GUI and I think I have to be more familiar with python, before I start 
this project.

Any hints/links are welcome. As a next step I will have a look at pythoncard. 
But first, I have to compile wxPythonSrc-2.4.2.4.tar.gz, because the rpm, 
which is included in the SuSE 8.2 distro is too old.

Al



More information about the Tutor mailing list