Hacker News new | past | comments | ask | show | jobs | submit login

This is one of the absolutely essential tools for anyone who writes a non-trivial amount of shell scripts.



Maybe it says something about the people I work with, but I've never seen a fully valid shell script, over 20 lines long, that handled spaces in paths and command errors properly, that didn't first go through ShellCheck. I've noticed that hardcore *nix people are usually some of the worst offenders, with their phobia of spaces, from years of broken shell scripts, completely preventing them from even thinking about the possibility of a space in a path, with some considering the space the bug, rather than its handling.

I've found that the best way to introduce someone to ShellCheck is to run it on their script, right in front of them, with most saying something like "How did I not know about this?". Linters are great!


The kind of issues shellcheck catches are mostly of the "didn't learn shell (and didn't believe that shell was a language that had to be learned)" kind. Or to put it another way, once you have a good hang of the shell language's peculiarities (which differ from most general-purpose languages, but are fairly self-consistent with a few high-frequency exceptions) ... well, less of your bugs are ones that shellcheck can catch.

I consider it an example of the general trend against learning domain-specific languages.


Oh good heavens, my friend.

My boss and coworker just spent the weekend on seven million files on my script.

find . -type f -print0 | xargs -0 (cygwin) sed 's/\ff//'

They think me a genius. This is nothing.


Did your regex get munged there? \f (form feed) is something I've never come across (well maybe back in BBC basic?) - what's the context of removing it/them (I'm guessing only pairs \f\f) from 7M files?


I have.

There are a few simple rules that, once you learn them, eliminate those kinds of problems. The main one is always use double-quotes around variable dereferences. The second is learning a few patterns, like find ... -print0 | xargs -0 ...

But even after you've learned those simple rules, shellcheck is still useful. It will find fewer problems, but that's a good thing, that means you learned something :-).


I can and do write shell scripts all the time which properly handle spaces, without ShellCheck. Not to say that it isn’t good to use, especially in a professional environment, but it’s not that hard. For parallel processing, xargs -0 and find -0 are your friends!


Agreed. I have it built into my vim editor, running after saves. Not only does it help catch errors, it catches potential errors, poor formatting and has become an amazing learning tool. Bash isn’t my favorite language, but many of the issues I had with it are no longer relevant.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: