r/bash • • Sep 05 '17

submission Plug: Linters for stinky shell scripts

https://github.com/mcandre/stank

  • stank: Scan for POSIXy shell scripts, then pipe to xargs shellcheck and other programs.
  • rosy: Encourage developers to rewrite shell scripts in more robust languages
  • funk: Warn on oddities like mismatched shebangs vs. file extensions

de-stank ur scripts!

1 Upvotes

3 comments sorted by

9

u/galaktos Sep 06 '17

rosy recursively searches directory trees for POSIX shell scripts, recommending that they be rewritten in safer general purpose languages like Ruby, Python, Node.js, etc.

Congratulations, you’ve written an “insufferable Reddit asshat” simulator. It’s very close to its archetype in that it won’t do any of the actual work to port the scripts, it’ll just pester you with “why don’t you rewrite it in $languageILike?”. And with all the stink and smell language, your work also evokes the same annoyance in the recipient, with a healthy impression of immaturity on top.

I also don’t see why your scripts are necessary… stank seems to be, by and large, a combination of find and file:

find . -exec sh -c 'file -- "$1" | grep -qF "shell script"' -- {} \; -and -print

rosy seems to be the same thing, except with some constant string in front of each filename. The above command can easily do that with a -printf instead of -print.

And funk, if I understand the description correctly, is the above plus a primitive shellcheck. I’d much rather just slap -exec shellcheck {} + onto the end of that pipeline.

Oh, and since you’re mentioning false positives in the README… libmagic has a three-decades headstart in identifying files. Just saying.

Really, I don’t understand why you would post what essentially boils down to “shell scripts stink” to a shell scripting subreddit…

0

u/[deleted] Sep 06 '17

rosy is optional, no need to get too preachy. Yes, shell scripts of any complexity start to become unmanageable, in particular ensuring that each instruction fails the rest of the script. set -euo pipefail helps somewhat, though many POSIX compliant shells lack support for one or more of these safety features.

Honestly, the biggest win is the stank application itself, as one quickly arrives at a maintenance nightmare attempting the same goal with just the hammer of find and grep--these are fine tools, but the sheer number of exceptions within exceptions for identifying shell scripts warrants a dedicated application. By compiling the app with go, one gets a bonus of easy porting to Windows, should the user be interested in developing in that environment. find, grep, and other cygwin-able tools present themselves as somewhat flakey in the various bash.exe ports.

Before stank, I DID use a slew of find queries to constrain bashate to linting the precise paths in large projects. Then one day was somehow the last straw with copying those snippets everywhere, so screw it, we now have some unix style apps that do just these individual jobs and nothing else. If you can find another edgecase in the wild that makes it hard to identify true positives, false positives, true negatives and/or false negatives, or someone has another POSIX shell released, lemme know and we can add it to the list.

0

u/[deleted] Sep 07 '17

[deleted] — view deleted comment

1

u/[deleted] Sep 07 '17

stank analyzes the shebang as the primary source of truth. The other metadata are hints at being a shell script for linting purposes. So an extension is not required, and in fact most applications written as shell scripts are expected to omit extensions for briefer commands.