TEMP_DIR=$(mktemp -d "${TMPDIR:-/tmp}/XXXXXX") \
  || {
    printf '%s\n' "ERROR creating a temporary file" >&2
    exit 1
  }

# when the program exits, it tries to remove the temporary folder.
# this code is executed even if the process receives a signal 1,2,3 or 15.
trap '[ "${TEMP_DIR}" ] && rm --recursive --force "$TEMP_DIR"' EXIT

touch "${TEMP_DIR}"/tempfile
