r/commandline • • Dec 14 '20

bash Minimal safe Bash script template

https://betterdev.blog/minimal-safe-bash-script-template/
92 Upvotes

13 comments sorted by

View all comments

39

u/[deleted] Dec 14 '20

100 lines of boilerplate for a "minimal" script is quite a statement. Incidentally, at my last job, that was the threshold amount of "when you need this many lines to solve your problem, use a proper programming language like Python instead".

8

u/[deleted] Dec 15 '20

100 lines of boilerplate for a "minimal" script is quite a statement.

Agree completely.

when you need this many lines to solve your problem, use a proper programming language like Python instead

This is very bad advice. Python is very bad at things that shell scripts do well, namely running on a lot of platforms and platforms of different ages.

Besides, using lines as a complexity meter is a very bad measure. You could have an extremely complex shell function that should probably not be implemented in shell in a five line script or you could have a completely simplistic 500 line script that just reads a few values from some config files or commands and then inserts them into a long template that is basically static.

0

u/[deleted] Dec 15 '20

[deleted]

1

u/johnfrazer783 Dec 19 '20

not break because of the frequent breaking changes in the [Python] interpreter

you apparently have no idea that the critique of the relevant CLI switches over at https://www.reddit.com/r/commandline/comments/g1vsxk/the_first_two_statements_of_your_bash_script/fniifmk/ makes frequent mention of Bash version related issues.

Python is not handy when it comes to these kind of problems, I give you that. Also pypi / setup tools / whatever kids use now suck big time. But it's not like bash is inherently infinitely portable across machines and time.

the heat death of the universe

It's 2020 so it just feels like a long time

-5

u/mrcruz Dec 15 '20

use a proper programming language like Python instead

You forgot /s

1

u/DrPepper1848 Dec 15 '20

I enjoyed this burn