Your script appears to be broken - one fix involves using the `:` builtin:
```sh
: XDG_CACHE_HOME:="$HOME/.cache"
```
But, a different technique is required since these variables need to be exported, as you mention.
Under that, it would be an improvement to make the script idempotent, quote the directories, and use lowercase variable names:
```sh
mkdir -p "$cache_dir" ...
```
This blog appears near the top of search results, so I think other people will benefit from these improvements.
Edwin Kofler