Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The more I write Python, the more I hate the shell (bash) script


if ["foo" = "foo"]; then
   echo "expression evaluated as true"

Guess what is error? I need a space after [, that is so hard to debug and non-sense, in Python, which is short and easy

if "foo" == "foo":
    print "expression evaluated as true"

As Python is avaliable in most system now, do you think it is a good chance to abandon shell script for new function and move to Python?

For those you are still writing new shell script, what are the reason?

share|improve this question

closed as not constructive by Sven, Khaled, RobM, Dennis Williamson, EEAA Jun 4 '12 at 12:31

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 2 down vote accepted

I still write very elaborate scripts in bash. The reason? Mostly because I'm used to it and bash is present on all systems (just make sure you don't do #!/bin/sh because you might have dash on some systems...).

Another reason is very tight integration with system commands.

A good reason I want to start getting used to perl or python, is because bash has no exceptions. It keeps running the script if there is an error you forgot to catch. And even doing "command || exit" won't work, because it doesn't work in pipes.

share|improve this answer
You can use set -e and it will exit on every error. – Martin Ueding Mar 16 '14 at 16:52
Except that it will also stop your script if you grep and get no match (which can be a perfectly normal situation). – Halfgaar Mar 16 '14 at 17:32
If you put that grep into an if, it will not stop the script. But yes, it is not as fine grained as exceptions. I do like Python more than Bash. – Martin Ueding Mar 16 '14 at 19:04
If you put grep somewhere in a pipe in an if, it does stop the script, though. – Halfgaar Mar 17 '14 at 8:07
This is the point why Bash is hard to really understand. I do not know the exact rules of the exist status, and I am just glad that Python exists. – Martin Ueding Mar 17 '14 at 12:48

Simple. 1) subprocess is annoying to chain. 2) It's easier to type for f in * ; do foo "$f" ; done as a one-off than to write a Python script to do the same.

share|improve this answer
pbs ( is a good alternative (need to install separately) – Howard Jun 4 '12 at 8:18
your link is a 404 and duckduckgo told me "PBS will no longer be supported. Please upgrade here: " – Johannes Aug 28 '13 at 13:47

Personally, I use both shell scripting and Perl scripting. When I need to deal with system commands mostly, I find it easier to write a shell script.

In other cases when I need to use some library which I could not find its equivalent in shell or does not know a command that can do it easily, I switch to Perl. This is the case when I need to connect to a database. I use Perl DBI module. I am talking about Perl, but the same idea applies when talking about Python.

It is a good idea to master both. Sometimes, you need this and in other cases you need the other.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.