bash Vs python ??

Ville Vainio ville.spammehardvainio at
Wed Nov 5 08:40:43 CET 2003

William Park <opengeometry at> writes:

> It depends.  My guess is Bash would be more suitable for "automated
> testing scripts", since you'll be calling lots of utilities.

os.system, os.popen family, pexpect...

In python it's much easier to process the output and produce the input
of the utilities.

Bash is good for throwaway one liners, Python is good for scripts that
you *gasp* save to a file and might also execute later. You never
know, you might want to extend the testing system later on, perhaps
developy advanced logging facilities etc. 

The shell has one advantage over Python, though: it can be executed in
the environment of current shell (i.e. '.'), so you can
change the environment variables in the surrounding environment. In
python you would have to do 

export MYENVVAR = $(python

If that is what you need, you might want to use bash. Otherwise, use
python. And even if you need that, you might want to generate the bash
script in a python script.

A good rule of thumb is: The less non-python stuff you have around,
the better. Non-python parts of any given system are invariably the
ones causing most of the problems :-).

Ville Vainio

More information about the Python-list mailing list