Hacker News new | ask | show | jobs
by endemic 3841 days ago
Maybe it's my lack of experience with Bash, but I feel the same way. While I generally find most interpreted languages easy to parse, bash just looks like Greek to me. I'd be curious to know what advantages a Bash script would have over, say, a Python script (aside from the obvious Python dependency).
3 comments

I use bash pretty regularly in the devops/sysadmin world pretty often. It can do some wonders, but it has some /serious/ issues.

That said, the reason it beats Python and all is simply because it's almost guaranteed to be on any *nix server you'll log into. Solaris, BSD, some networking equipment - it'll be there. Python? Maybe. Python 2.7? Sorry, your sysadmin didn't add that yum repo and we're stuck on 2.6 at best.

You'll have similar problems if some packages aren't installed on a machine, but as long as your scripts are using the usual gnu packages, you should be good (with some exceptions of course).

It's a crappy problem to have, but it's probably not going to go away, especially in prod environments. It's just easier to run bash than to get your sysadmins to do some damn patching (or management to approve it..) than to try/potentially fail with anything else.

Then again, I'm all for using /bin/sh for everything. :)

In bash simple things are simple to write, get and read. And you don't need to deal with imports to do them, it's out of the box. Execute any ex. file? Just write down its path. Don't want to pause the main program? Add & after that path. Write output to file? Just append > filename after the command. Regex matching? Just use if [[ string =~ pattern ]]; ... lots of useful stuff, few keystrokes away. Python can do these things and more, but there is often a lot of tiresome overhead with recalling library names, dealing with local namespaces, method parameter positions, type casts just doing the most elementary stuff. This high-level complexity is useful for big and monster-big collaboration projects, but is wonderful to avoid when possible. Shell makes that often possible and is fun to use as well.
Not only just the environment dependency, but also human dependency. Being able to script in bash is considered a skill that any sysadmin would have. If you write bash scripts you can pretty much assume any sysadmin can read/write it. They may or may not know python.