Interfacing with people is never easy.
export CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}"
export CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}"
...
XDG_*_DIRS are a bit more complicated, but nothing that can't be solved with a simple for-loop in any modern programming language.