bash Vs python ??

O

Omar Khalid

hello experts,
i have been assigned a project in which i have to do a lot of
command line processing by writing "automated testing scripts "
for a software on unix platform .

what would be a better option in this scenario bash (unix shell scripting
) or python ?
plz give me advantages & disadvantages of both . any web links ?

TIA
 
R

Rene Pijlman

Omar Khalid:
what would be a better option in this scenario bash (unix shell scripting)
or python ?

Python is a regular programming language, with high level data structures,
modules, classes, exception handling etc.

Bash is not.
 
P

P

Omar said:
hello experts,
i have been assigned a project in which i have to do a lot of
command line processing by writing "automated testing scripts "
for a software on unix platform .

what would be a better option in this scenario bash (unix shell
scripting ) or python ?
plz give me advantages & disadvantages of both . any web links ?

probably a mixture of both is appropriate.
bash is tuned for calling system commands
directly and piping the output from these
together in various ways. But it can be
woefully inefficient and awkward for certain
things, like string manipulation or looping
for e.g. You may be better doing something like:

bash_script | python_processing

Pádraig.
 
V

Ville Vainio

probably a mixture of both is appropriate.

I don't see any reason to use bash if python has already been
introduced to the mix. Using standard unix tools like xargs, find
etc. from python is a different thing altogether.
 
W

William Park

Omar Khalid said:
hello experts, i have been assigned a project in which i have to do a
lot of command line processing by writing "automated testing scripts "
for a software on unix platform .

what would be a better option in this scenario bash (unix shell
scripting ) or python ? plz give me advantages & disadvantages of
both . any web links ?

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

Ville Vainio

William Park said:
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. '. myscript.sh'), so you can
change the environment variables in the surrounding environment. In
python you would have to do

export MYENVVAR = $(python calcvalforvar.py)

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 :).
 
W

William Park

Ville Vainio said:
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.

This is total misrepresentation that can only come from a recent
newcomer to Python. :) Python has data structures because it's general
programming language. But, Bash is much more expressive and convenient
when it comes to calling utilities.
 
A

Anand Pillai

bash vs python?

Does it make sense to compare a rudimentary unix shell with
minimal capabilities to a powerful programming language
like python? I dont feel so.

-Anand
 
V

Ville Vainio

bash vs python?

Does it make sense to compare a rudimentary unix shell with
minimal capabilities to a powerful programming language
like python? I dont feel so.

Some people's idea of optimization is selecting the worst tool that is
tolerable for any particular tasl. That way, no tool feels
neglected. If no language of "just right" amount of suckage is
available at the moment, it needs to be implemented.
 
J

John J. Lee

Ville Vainio said:
(e-mail address removed) (Anand Pillai) writes: [...]
Some people's idea of optimization is selecting the worst tool that is
tolerable for any particular tasl. That way, no tool feels
neglected. If no language of "just right" amount of suckage is
available at the moment, it needs to be implemented.

:))) You have that right!


John
 
Y

Yu Wang

In my experience, for "automated some scripts" less than 50 lines, no
heavy file handling, bash is more suitable. Otherwise, Python wins.
You can write rather faster if the script is composed of different "call
commands" in bash. But if you have to deal with intermediate file/string
, to use bash is a pain. I always change to Python.
Afterwise, everything you can use in bash, you can find certain ways in
Python.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top