/BreakingBash

Bash Script tips, tricks, functions, templates, best practices, etc.

Primary LanguageShell

Breaking Bash

Bash Script tips, tricks, functions, templates, best practices, etc.

General

BASH STRICT MODE

#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

-e 		Immediately exit upon any non-zero exit code, just like c exits 
		after a seg fault or syntax error in python
-u 		Throws an error and immediately exits when you refernce a 
		variable that is undefined
-o pipefail	Prevents errors in a pipeline from being masked
IFS
names=(
   "Aaron Maxwell"
   "Wayne Gretzky"
   "David Beckham"
   "Anderson da Silva"
 )
WITHOUT STRICT WITH STRICT-MODE IFS
Aaron Aaron Maxwell
Maxwell Wayne Gretzky
Wayne David Beckham
Gretzky Anderson da Silva
David
Beckham
Anderson
da
Silva

Style Guide

Resources

  1. Advanced Scripting Guide
  2. Bash Guide
  3. Bash Style Guide
  4. Linting
  5. Strict-Mode
  6. Exit Traps
  7. Template
  8. Argument Handling