bash

  • array syntax [@]
  • --posix for sh mode
  • &> 2>&1 redirects stderr and stdout

snippets

#!/usr/bin/env bash
# trap errors
set -Eeuxo pipefail
trap "ERROR TRAPPED" ERR
_install_stuff(){
    # setup dir
    local OLD_DIR="$( pwd )"
    local CUR_DIR="$( dirname $0 )"
    cd ${CUR_DIR}
    # ensure binary
    local ANSIBLE_CMD="ansible-playbook"
    if ! [ -x "$(command -v ${ANSIBLE_CMD})" ]; then
        ANSIBLE_CMD="${HOME}/.local/bin/ansible-playbook"
    fi
    # glob
    for dir in ${CUR_DIR}/*/; do
        cd ${dir}
        ${ANSIBLE_CMD} ./*-playbook.yaml
        cd ..
    done
    # return to calling dir
    cd ${OLD_DIR}
}
# run and cleanup
_install_stuff
unset _install_stuff
THING=$(<somefile.txt)
wg set %i private-key <(su user -c "export PASSWORD_STORE_DIR=/path/to/your/store/; pass WireGuard/private-keys/%i")