Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

Shellcheck is amazingly impressive at catching issues with shell scripts. It makes it very hard to write a shell script that does the wrong thing.

Also, look at oilshell[1]; it is bash compatible out-of-the-box, but has several options to make it incompatible, but safer (e.g. no field splitting of parameter expansion by default, making quotes much less needed).

1: https://www.oilshell.org/



sort by: page size:

Shellcheck [1] has a lot of issues with this script. You might consider refactoring it a little bit to pass without errors. Some of the warnings could probably be ignored.

[1] - https://www.shellcheck.net/


I'd recommend shellcheck[1] to help avoid common pitfalls with bash/sh, particularly in regards to word splitting.

[1] https://www.shellcheck.net/


Looks like that script could benefit from a couple of rounds of ShellCheck. http://www.shellcheck.net/

Is there a script to check for these pitfalls? (And offer example solutions?)

Has anyone forked bash to remove or fix these pitfalls, while maintaining maximum "bashness"?

edit: http://www.shellcheck.net/


Shellcheck helped me learn a lot about bash.

https://www.shellcheck.net/


I know enough bash to know a relevant shellcheck rule... Not sure that's enough to use it safely. :)

https://github.com/koalaman/shellcheck/wiki/SC2124


Shellcheck helps a lot with this, I won't write shell without it anymore: https://www.shellcheck.net/

advanced bash scripting guide: https://www.tldp.org/LDP/abs/html/

also, https://www.shellcheck.net/ not reading, but pretty neat. static code analysis for shell scripts, points out common errors.


I highly recommend ShellCheck[0] if you're writing any bash. With the warnings and stylistic advice it provides, I feel like I can actually be confident that my scripts are doing what I think they're doing.

[0]: https://github.com/koalaman/shellcheck


Nice script.

It's... uhhh... not shellcheck-clean.

https://shellcheck.net/


Writing bash scripts becomes a lot less error prone with shellcheck[1]. Syntastic for vim integrates well with it.

[1]: https://github.com/koalaman/shellcheck


Best used in combination with shellcheck (https://www.shellcheck.net/), which checks your shell scripts for bugs.

For bash scripting: have you seen shellcheck? It's a very solid first-pass for any script, and the codes it emits have excellent documentation: https://www.shellcheck.net/

Shellcheck will find a broad variety of unsafe shell operations, including most (all?) of the issues on this page: http://www.shellcheck.net/

Related, I love to send my bash scripts though https://www.shellcheck.net/

I'm being flippant, because shell scripts are so inherently error prone they're to be avoided for critical stuff like this.

If you _absolutely_ must use a shell script:

0. Use shellcheck, which will warn you about many of the below issues: https://www.shellcheck.net/

1. understand how quoting and word splitting work: https://mywiki.wooledge.org/Quotes

2. if piping files to other programs, using `-print0` or equivalent (or even better, if using something like find, its built in execution options): https://mywiki.wooledge.org/UsingFind

3. Beware the pitfalls (especially something like parsing `ls`): https://mywiki.wooledge.org/BashPitfalls

(warning: the community around that wiki can be pretty toxic, just keep that in mind when foraying into it.)


shellcheck, whilst not a script itself, I do find it useful when writing them.

- https://github.com/koalaman/shellcheck


I guess this is as good of a time as any other to remind people to use the "unofficial" Bash strict mode:

https://gist.github.com/robin-a-meade/58d60124b88b60816e8349... [^1]

And always, always, use ShellCheck (https://www.shellcheck.net/) to catch most pitfalls and common mistakes on this powerful but dangerous language that is shell scripting.

[^1]: I think this gist is better than the original article in which it is based, because the article also suggested changing the IFS variable, which is not that good of an advice, so sadly the original text becomes a bad recommendation!


Pretty sure shellcheck ( http://www.shellcheck.net/ ) has a lot to say about this faulty script...
next

Legal | privacy