We are eventually going to look at using bash and similar shells for scripting as the bad old days.
Which would you rather have, a script that was too clever by half, or a system architecture that was too clever by half?
It's a whole lot easier to fix the script than it is the system architecture.
Together with GitHub user xPMo, I created a Shellcheck REPL tool (https://github.com/HenrikBengtsson/shellcheck-repl) that validates your Bash commands using ShellCheck _before_ they are evaluated. For example,
$ words="lorem ipsum dolor" $ echo $words ^-- SC2086: Double quote to prevent globbing and word splitting.
It was a toy project at first, but since I've learned so much about Bash from using it, I now have it enabled all the time.
I do have one suggestion: you have it ignoring "SC2154: 'var' is referenced but not assigned" by default, which makes sense on the command line because you're often not assigning and then referencing the same variable in a single command. But, I think it would be useful to have a similar warning like "SCREPL01: 'var' is not defined in the local environment," or something, which you might implement in shellcheck-repl itself. That rule could simply check to see if 'var' exists in the current shell's environment or if it's defined in the user's current command.
I think bash is simple enough that you might not have to a full-blown parse on the input to pick out instances of variable use (just look for 'export var', 'unset var', 'var=', and the like). You'd also want to take into account special variables like $RANDOM and $HOSTNAME, but that's pretty trivial.
> You'd also want to take into account special variables like $RANDOM and $HOSTNAME, but that's pretty trivial.
It seems like ShellCheck is already aware of these special Bash variable, e.g. 'echo $RANDOM' will not trigger SC2154 (or even SC2086 that otherwise asks you to quote variables).
Bash Pitfalls - https://news.ycombinator.com/item?id=24401085 - Sept 2020 (111 comments)
Bash Pitfalls - https://news.ycombinator.com/item?id=10068567 - Aug 2015 (38 comments)
Bash Pitfalls - https://news.ycombinator.com/item?id=6790169 - Nov 2013 (54 comments)
Common Bash Pitfalls - https://news.ycombinator.com/item?id=869560 - Oct 2009 (25 comments)
Bash Pitfalls - https://news.ycombinator.com/item?id=52700 - Sept 2007 (1 comment)
It's dang's choice to have two windows open- one with the comment box, and one with the 'past' page- and to read which ones have discussion with his human eyes, and then to type out the relevant information into the comment box. I'm vicariously offended that anyone would think this is a task that should, or even could, be even partially automated.
https://github.com/dylanaraps/pure-bash-bible
>The goal of this book is to document commonly-known and lesser-known methods of doing various tasks using only built-in bash features. Using the snippets from this bible can help remove unneeded dependencies from scripts and in most cases make them faster.
Interesting, although on a quick skimming most of the functions listed there are wrappers over... printf?
* https://www.shellcheck.net/ — linting tool to avoid common mistakes and improve your script
* Bash Practices: https://mywiki.wooledge.org/BashGuide/Practices
* Bash FAQ: https://mywiki.wooledge.org/BashFAQ
* safe ways to do things in bash: https://github.com/anordal/shellharden/blob/master/how_to_do...
* better scripting: https://robertmuth.blogspot.in/2012/08/better-bash-scripting...
* robust scripting: https://www.davidpashley.com/articles/writing-robust-shell-s...
I am hopeful that the page will have a screenshot, when I am able to access it.