Skip to content

Instantly share code, notes, and snippets.

@dan4thewin
dan4thewin / bash4thewin.md
Last active June 19, 2024 00:33
Bash idioms and tools

This page collects a set of bash scripting idioms and tools for easy reference.

Improved Error Detection: set -e and set -u

With -e (errexit), bash exits immediately if an unchecked command exits with a nonzero value. A checked command is part of a while, until, if, elif, or an expression with && or ||. Everything else is unchecked. For a pipeline, only the last command is considered. Adding "or no-op", || :, ensures a command is safe, e.g., do-something | grep 'may_not_match' || :. NB. Calling a bash function in a checked context effectively disables -e for all commands in the function. Use the optional shellcheck, check-set-e-suppressed, to alert on this.

@dan4thewin
dan4thewin / unit_testing_with_cpp.md
Last active December 13, 2020 03:00
Unit Testing with the C Preprocessor

Unit Testing with the C Preprocessor

Motivation

I want an approach to unit testing with a near-zero learning curve that works practically everywhere, with no exotic dependencies and no performance penalties.

Simplicity is the height of sophistication. - Clare Boothe Luce