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 |