Shell
Get script dir
Section titled “Get script dir”SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
Check if command available
Section titled “Check if command available”With command
if ! command -v aws &> /dev/null; then echo "aws could not be found" exitfi
with type
if ! type uuid >/dev/null 2>&1; then echo "uuid command not found!" exitfi
Set default value to variable
Section titled “Set default value to variable”variable=${1:-default_value}
Expression | x set and not null | x set to null | x is unset | x after expression |
---|---|---|---|---|
${x:-default_value} | $x | default_value | default_value | $x |
${x-default_value} | $x | $x (null string) | default_value | $x |
${x:=default_value} | $x | default_value | default_value | default_value |
${x=default_value} | $x | $x (null string) | default_value | default_value |
set -Eeuo pipefail
Section titled “set -Eeuo pipefail”Sources: vaneyckt.io / gnu.org
- e/errexit: cause a bash script to exit immediately when a command fails
- E: any trap on ERR is inherited by shell functions, command substitutions, and commands executed in a subshell environment. The ERR trap is normally not inherited in such cases. (means that trap is triggered even if -e is set)
- u/nounset: treat unset variables as an error and exit immediately
- pipefail: sets the exit code of a pipeline to that of the rightmost command to exit with a non-zero status
- e/xtrace: Print a trace
set -x for debugging
Section titled “set -x for debugging”if [[ -n "${TRACE-}" ]]; then set -o xtrace; fi
Sources: tldp.org
# trap EXIT and kill awslogs processtrap "killall awslogs" EXIT
Testing TLS/SSL/HTTPS certs
Section titled “Testing TLS/SSL/HTTPS certs”https://github.com/drwetter/testssl.sh
./testssl.sh https://my-url.foobar.baz