#!/usr/bin/env bash - Use bash found in the environment path. Protects against not knowing where user's bash is installed.
set options -xeuo
Commonly used options:
-x: turns on debug output, logging each command as it is executed-e: causes the script to exit on most command failures (non-zero exit codes)-u: treats unset variables and parameters other than the special parameters @ or * as an error when performing parameter expansion-o pipefail: causes the script to exit if a command in a pipeline failsMany more options available: https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
$@ - All of the arguments as individual strings“$*” - All of the arguments as a single string$# - The number of arguments$1..n - Where n is an integer, the nth argument in the list$0 - The command name$? - The last exit code$IFS - Internal/input field separator (defaults to combo of space, newline and tab)Declaring a function (needs to happen before use):
function <function_name> { … do things … }
- or -
<function_name>() { … do things … }
$1..$n.