0

What's your rationale for when to write a Bash script and when to use a more powerful scripting language (Python, Perl, Ruby, ...)?

I'm finding that very simple scripts are nicer with Bash, but many of those get quite fancy over time, and it never seems like a good idea to rewrite the whole thing. That's why I'm leaning towards always using Python for all scripting.

But since Bash seems to be the the lingua franca of Linux scripting, is that something a responsible system administrator would do?

futlib
  • 111
  • 1
  • 2
    This isn't really a technical question, but more of an opinion. You should use what you're comfortable with and it doesn't hurt to have experience with more than one scripting language. Each have their place & strengths/weaknesses. You should rephrase your post into more of a question.. "I want to do , is this the best language/way to go about accomplishing ?" – bmurtagh Nov 13 '12 at 14:35

3 Answers3

4

The answer on this always comes down to 'use what you know'. Depending on the purpose I regularly script in over half a dozen different languages. Most of the folks here will likely say the same.

Tim Brigham
  • 15,545
  • 10
  • 75
  • 115
2

Some tools/environments may be marginally better adapted to certain tasks than others, but when it comes to distinguishing between bash, python, perl and ruby (and similar) for administrative scripting, you should consider (if not favour) the human factors:

  1. Is maintainable? (You touched on this in your question.)
  2. Is it usable by other people within your organization? If you're (somehow) the only admin in your company who knows any python, it probably isn't be the right language to use, even if it makes shorter or more efficient scripts than the equivalent bash.

If the environments are equally available on your systems, and if many languages fit the bill, choose the one you're most comfortable with. Why? It will shorten development time, facilitate debugging, increase maintainability and at least not reduce institutional usability.

My subjective preference is for bash as well, but that doesn't matter: it's only my choice because I'm comfortable with it (say, I know how to manipulate iptables without looking up documentation).

msanford
  • 1,477
  • 15
  • 28
0

Also, use the right tool for the job. Does your problem require more flexible data structures than bash provides?

glenn jackman
  • 4,630
  • 1
  • 17
  • 20