Python for bash replacement

When I started learning Python, I was looking for a programming language that would replace BASH, AWK and SED. I am a C/C++ programmer and as such I better invest my time into studying C and C++. Instead, every time I needed some complex script I opened up a book on BASH and refreshed my knowledge. And since bumping into boundaries of what BASH can do is relatively easy, I always opened awk/sed book few minutes later.

Actually, this is quiet common. Once in a while I see my¬†colleagues, just like myself,¬†open up a book on BASH. The problem is that because we don’t actively program BASH, the knowledge and experience that we gain from this experience wear out over time. So next time we approach, so we have to repeatedly study BASH stuff over and over again. And again, this is not only BASH I am talking about, but also AWK and SED.

It is utterly broken state of affairs and I wish there was a solution. Unfortunately there is no solution yet. The good thing is that with some effort the solution may arise. I am talking about Python programming language.

Needless to say that Python can do everything that BASH can do. However, it was never designed as shell environment and as such it is hardly convenient.

For instance, running external commands is easy. You should use subprocess module to run the command and there you go, you have both return value and the output. But this is miles away from convenience of simply typing the command and hitting enter.

Another issue is input/output redirections and piping. Regular shell does this with ease. Python obviously does this as well, but not without a hassle of importing the right module and creating the right object, etc.

On the other hand things are not that bad. For instance implementing command line should be somewhat easy in Python because it has native support for completion (which it uses in its own command line interface).

There is a project that makes few steps in the right direction. I am talking about IPython of course. Unfortunately, I doubt that IPython will ever be able to replace BASH. It was never their goal. Even though IPython developers implemented some features that make IPython command line a little down to earth, I am in doubt they will continue moving in this direction. Also, I must say that IPython evolves quiet slowly.

What do you think? Will Python ever be able to replace BASH?

Did you know that you can receive periodical updates with the latest articles that I write right into your email box? Alternatively, you subscribe to the RSS feed!

Want to know how? Check out
Subscribe page


  1. Pavel says:

    That’s what Perl was intended for. :)
    Merry Christmas!

  2. Shai says: is an interesting concept for ruby.

    In any case though … don’t see BASH going away anytime soon happening.

  3. Oz says:

    Or simply use IPython as your shell. I know a guy that uses Matlab as shell :-)

  4. Angel Genchev says:

    Hmm. Once I had to fix someone’s python code, so tried to learn it. Easily got frustrated with the weird syntax. It makes reading the code very difficult. The only good thing I can say – it’s interpreter is fast and there’s a lot of code written in python.
    When the speed is not important, I use php instead. It`s far more readable (C/C++ -like syntax) and also strange to use for shell scripting. Didn’t test the CShell

  5. Angel Genchev says:

    Found another interesting alternative – Node.js for shell. it’s javascript. A good article about it:

  6. Jeff says:

    Ever tried playing with IPython? I love python and I create utilities all of the time with it. Love the fact the you can extend the capabilities of your code with modules… like using paramiko or use of jython to use java modules. Wait till you start playing around with Ruby… really nice.

  7. Basic usage BackTrack Linux

    Python for bash replacement – Alex on Linux

Leave a Reply

+ 8 = ten