Useful bash scripts

Collection of useful bash scripts

Copy env variables to script:

#!/usr/bin/env bash

Strict mode for execution of code:

set -euo pipefail

Script conditional arguments:

if [[ -z "$string" ]]; then
  echo "String is empty"
elif [[ -n "$string" ]]; then
  echo "String is not empty"
fi

Range loops:

for i in {1..5}; do
    echo "Id: $i"
done

Example function:

function myfunc() {
    echo "Example $1"
}
myfunc "Arg"