Your periodic reminder that Shellcheck is awesome and should be used everywhere...

#ShellCheck

Holy crap! That 50 line #ShellScript, which includes child process management and signal handling, not only works, but #shellcheck only whines about two things, both of which I know don't matter.
I'm using #shellcheck's excellent #haskell GitHub workflow to produce statically linked Haskell binaries. It's curious, however, that ghc-9.0.4 produces a binary that's roughly 1MiB in size, whereas 9.4 produces a whopping 30MiB binary. Haven't tested the later ghc versions yet, but I hope they're a bit more conservative w.r.t. size...

Finally had a reason to figure out what shellcheck means with "prefer mapfile…" https://www.shellcheck.net/wiki/SC2207

Also, https://www.shellcheck.net/wiki/SC2068, quote array expansion.

Yes, I need to read a file to an array, each line may contain spaces, and I need to pass each line as an argument to another thing.

mapfile -t lines < inputfile
dostuff "${lines[@]}"

actually does what I need, without a BUNCH of headaches.

It only took me a bit more than a quarter of a century before I got here 🙂

#bash #shellcheck

ShellCheck: SC2207 – Prefer `mapfile` or `read -a` to split command output (or quote to avoid splitting).

Lifegoal unlocked!

Ein Shellscript für eine Installationsroutine geschrieben, #shellcheck ausgeführt und auf Anhieb dort keine Fehler oder Notizen ausgelöst \o/

I just learned ShellCheck is written in Haskell and I can't stop laughing.

Not because I don't like Haskell — quite the opposite, it's high on the list of languages I hope I can get real day-to-day working experience with — but because it's so rare to get a popular project and find "the easiest way to install is using Cabal" in the readme.

#haskell #shellcheck #bash

@inlovewithpda #bash is great, I've developed many a helping monster script. But bash also is a beast when it comes to getting it right. It's helpful to use a #Linter (like #shellcheck for example).
Even more important is to know when you should drop your bash script, consider it a prototype and reimplement it with a language that suits the problem better.

Ran #shellcheck on my thesis's #Bash part and it detected like 6 errors. Some were false positives, but one was an actual problem. I was saving the passed arguments and needed to save them and temporarily remove all of them so that a sourced script doesn't exec them and it turns out that arrays in Bash are even more cursed than I thought.
I don't think I'm ever going to write shell scripts without shellcheck. Honestly it should be installed by default on every non-minimal #Linux distro.

edit: To clarify, the false positives were also things to be mindful of, specifically sourcing unknown command outputs, but it was search paths from guix, so it was fine in this very specific case.

Just a quick reminder: if you're writing #shell scripts, always use #shellcheck. It'll make your life so much easier! https://www.shellcheck.net/
#bash #linux #scripting #programming
ShellCheck – shell script analysis tool

ShellCheck finds bugs in your shell scripts

@klausman @nixCraft Applied a couple of minor fixes. It now at least passes #ShellCheck without complaints, which is good.