Daily Weekly Monthly

Daily Shaarli

All links of one day in a single page.

April 29, 2020

Defensive BASH programming - Say what?

Defensive BASH Programming

Nov 14th, 2012 | Comments

Here is my Katas for creating BASH programs that work. Nothing is new here, but from my experience pepole like to abuse BASH, forget computer science and create a Big ball of mud from their programs.
Here I provide methods to defend your programs from braking, and keep the code tidy and clean.
Immutable global variables

Try to keep globals to minimum
UPPER_CASE naming
readonly decleration
Use globals to replace cryptic $0, $1, etc.
Globals I allways use in my programs:
Bash Strict Mode

Use Bash Strict Mode (Unless You Love Debugging)

Let's start with the punchline. Your bash scripts will be more robust, reliable and maintainable if you start them like this:

#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
40 Free HTML landing page templates - DEV Community 👩‍💻👨‍💻

40 Free HTML landing page templates