Hacker News new | ask | show | jobs
by simias 4358 days ago
I've never understood why anyone would inflict oneself with bash scripting. If you really need something portable you should use standard /bin/sh anyway since bash is not installed by default everywhere (I believe many linux distros don't even ship with bash anymore, but a lightweight clone called "dash"?).

And if you don't care about portability out of the box, why not use... Well basically anything else? Perl, python, ruby, lua, scheme, whatever.

The only shell scripts I ever write are basically a list of command to execute sequentially. If I need something more complex (control flow, user input, proper error handling, nontrivial string manipulation) I switch to some other programming language, it's just not worth the pain.

3 comments

Many Linux distros ship with /bin/sh being dash, but they also come with /bin/bash. A lot of scripts obviously depend on bash, so distro maintainers have had to either fix them to depend only on POSIXy "sh" or just put #!/bin/bash at the top.

The reason to use dash instead of bash is speed and to a lesser extent memory usage. The goal isn't to stop needing bash, it's to speed up boot times etc. Or at least it was five years ago when this transition was happening.

When I write scripts, I often need to execute programs written in different languages. Writing such scripts in a languages like Python and Ruby is very clumsy.

Whereas the scripts I write in Ruby tend to rely heavily on a bunch of gems that add enormously to startup time. These scripts also often end up as stages in a pipeline executed from bash.

Fork/join shared-nothing parallelism is also very easy to do in bash, and is how I normally use more cores to get jobs done more quickly.

I don't know, I feel like POpen and friends in python just aren't as nice as doing 'thing-one | thing-two' kinda stuff, with some ifs, and some variables.