Bash (4 blogmarks)

← Blogmarks

BashMatic - BASH/DSL helpers for the rest of us.

https://bashmatic.dev/

A powerful BASH framework with 900+ helper functions to make your BASH scripting easier, more enjoyable, awesome looking, and most importantly, fun.

With Claude lowering the barrier to try things out, I’ve been using it to write all kinds of one-off bash scripts to help with various day-to-day things. I notice common patterns arise and certain nice-to-haves that are missing. It made me wonder if there was a library of bash scripting utility functions. Sure enough. Very cool project!

When in doubt, be consistent

https://google.github.io/styleguide/shellguide.html

Using one style consistently through our codebase lets us focus on other (more important) issues. Consistency also allows for automation. In many cases, rules that are attributed to “Be Consistent” boil down to “Just pick one and stop worrying about it”; the potential value of allowing flexibility on these points is outweighed by the cost of having people argue over them.

Lots of great tips in this style guide on writing good bash scripts.

Other good (general) advice:

When assessing the complexity of your code (e.g. to decide whether to switch languages) consider whether the code is easily maintainable by people other than its author.

GitHub - dylanaraps/pure-bash-bible

https://github.com/dylanaraps/pure-bash-bible

The goal of this book is to document commonly-known and lesser-known methods of doing various tasks using only built-in bash features. Using the snippets from this bible can help remove unneeded dependencies from scripts and in most cases make them faster.

I learned about this via Can anyone suggest me good Bash book filled with small examples only? : r/bash.

Other recommendations in that thread:

List of all ShellCheck Rules

https://www.shellcheck.net/wiki/

This is the root wiki page for ShellCheck which lists all of the rules that it enforces when checking your scripts.

Each rule links to a page that describes the issue, shows you an example of the problematic code, and a corrected version.

E.g. SC1003 Want to escape a single quote? echo 'This is how it'\''s done.' shows:

Problematic code:

echo 'this is not how it\'s done'

Corrected code:

echo 'this is how it'\''s done'