3 ms·
> 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
by einpoklum 5y ago
> 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 https://stackoverflow.com/q/7868818/1593077)
:-)
- jamesrr39 5y agoYou 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).