Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

While I understand the sentiment, I'm not sure how bash could ever be as maintainable as a something written in e.g. Python (or even better, a strongly-typed language).

The thing with bash is, it's great for tying things together and quick bits and pieces, but it's not set up for writing maintainable code. Arrays, functions, even if statements comparisons can all be done in bash (as first-class features), but are just... easier in other languages. And then think about the refactoring, linting, testing tools available in bash vs other languages. And then on top of that, there's the issue of handling non-zero return codes from programs you call; do you `set -e`, and exit on any non-zero return code even if you wanted to continue, or not `set -e`, ignoring any errors as your script just continues.

Personally, when I feel I want to use a function (or array, or other similar, non-trivial thing), in bash, it's time to reach for another language.

Having said that, there are some nice programs written in bash. https://www.passwordstore.org/ being one that comes to mind.



> e.g. Python (or even better, a strongly-typed language).

Python is strongly typed. Maybe you meant "statically"? (As opposed to dynamically.)


Yes, you are right, and statically is what I meant, thanks for the correction.


> Personally, when I feel I want to use a ... non-trivial thing ... in bash, it's time to reach for another language.

Then you must not be writing any bash at all. Functions are useful for almost anything beyond a one-liner script.

Typical functions used in innumerable non-trivial scripts:

* print_usage()

* die() (see: https://stackoverflow.com/q/7868818/1593077)

:-)


You are kind of right, I don't write much bash, but I do write some simple scripts that I can call quickly and easily (e.g. start this program with these args, write the log file here with the filename as the current date, etc). Although regarding "Then you must not be writing any bash at all"; I'm not sure how you could have deduced this!

With regards to `print_usage()` and `die()`, yes, I would reach for Python 3 then. The `argparse` module and `throw` are first-class members of the stdlib/language and are better and more standard between programs than if I threw together these myself (and with `throw` you get a stack trace, which is nice).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: