Skip to content

Shell

Terminal window
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

With command

Terminal window
if ! command -v aws &> /dev/null; then
echo "aws could not be found"
exit
fi

with type

Terminal window
if ! type uuid >/dev/null 2>&1; then
echo "uuid command not found!"
exit
fi
Terminal window
variable=${1:-default_value}
Expressionx set and not nullx set to nullx is unsetx after expression
${x:-default_value}$xdefault_valuedefault_value$x
${x-default_value}$x$x (null string)default_value$x
${x:=default_value}$xdefault_valuedefault_valuedefault_value
${x=default_value}$x$x (null string)default_valuedefault_value

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
Terminal window
if [[ -n "${TRACE-}" ]]; then set -o xtrace; fi

Sources: tldp.org

Terminal window
# trap EXIT and kill awslogs process
trap "killall awslogs" EXIT

https://github.com/drwetter/testssl.sh

Terminal window
./testssl.sh https://my-url.foobar.baz