4 ms·
I just tried to use it this morning. I had an if with [[ ]] and one with [ ] so I hoped for advice. No errors or warnings. Then I didn't bother using it anymore
by pvinis 6y ago
I just tried to use it this morning. I had an if with [[ ]] and one with [ ] so I hoped for advice. No errors or warnings. Then I didn't bother using it anymore. Furthermore, I switched the script to use deno!
- miduil 6y agoshellcheck won't force you to prefer one of the two variants, hence the difference is relatively subtle to a degree that even documentation is not superhelpful either: https://www.oilshell.org/blog/2016/10/12.html https://www.oilshell.org/blog/2016/10/12.html shellcheck will show you many more mistakes that are much more painful your example and also very common. Deno is definitively an interesting language, but Shell scripting is the gateway to bootstrap so many of your beloved programming languages. If your environment allows it always prefer a proper programming language over shell scripting. Shell scripts are meant for Unix operating system operations, setting few variables, combining certain data-sources, doing filesystem operations, ...
- maddyboo 6y agoA useful thing with conditionals is shellcheck will warn you not to write [ foo -eq 1 && bar -eq 2 ], but to write [ foo -eq 1 ] && [ bar -eq 2 ] or [[ foo -eq 1 && bar -eq 2 ]]. I do think it would be nice if shellcheck was more opinionated, or if it was possible to create rulesets that have stronger opinions. For example, I would personally like to enforce the use of double bracket conditionals in my scripts, but I know that others prefer the single bracket variety.
- ratsmack 6y agoWhat would be better is that undesirable syntax support is aggressively deprecated and ultimately removed.
- DrewRWx 6y agoWhich shebang was your script using? If it was #!/usr/bin/env sh then shellheck would report SC3010: In POSIX sh, [[ ]] is undefined. .
- pvinis 6y agoIt was with bash, not sh. Hm interesting.
- sigzero 6y agoThose are both valid in bash. If you were using posix sh it would error.