News for hackers. Stuff that matters.
Re:Bash functions are better than I thought by einpoklum on Sunday October 31, 2021 @02:45PM (#29059265)
> 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)

:-)

Re:Bash functions are better than I thought by jamesrr39 on Sunday October 31, 2021 @03:18PM (#29059531)
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).