Personally I'd like to adhere to to XDG Base Directory Specification to make my utility more portable.

However when doing so it requires me to re-implement for systems that do not have the XDG_ parameters implemented.

This on it's own is not much of a problem as the XDG Base Directory Specification covers this detailing what to do instead. For example if XDG_DATA_HOME is unset or empty use ~/.local/share instead.

However what to do if $HOME is unset or empty?

Should I adhere to the system wide options at least for where it is in the XDGBDS given (e.g. no $HOME but more /etc/something etc.)?

Honestly I have very little experience under which circumstances $HOME actually is empty, so it's hard for me to decide well here.

1 Answer 1


The HOME environment variable is set by all forms of user login, interactive and non-interactive, per the Single Unix Specification. It is also often set for per-user services, albeit that the SUS does not require this because such services execute outwith login sessions and the SUS only states a requirement for user login. It is almost always not set for system-wide service processes.

The XDG Base Directory Specification is mute on what to do when the HOME environment variable is not present. So really what to do is somewhat a matter of opinion, and a matter of what makes sense for the specific tool.

One could do what some softwares do when there is no HOME environment variable, and fall back to looking up the home directory field in the record for the current process's effective UID in the system account database. (Some of the tools in my nosh toolset do this, including ones that are trying to find things in $HOME/.config/; as also do the programs in the answer pointed to in further reading.)

But equally one do could what the cd command does, and just fail with an error message.

Or one could state that in such a situation only the system-wide directories are read and processed for the relevant files for one's program.

Do not default to writing to the system directories, though. There is a difference between per-user stuff and system-wide stuff.

Further reading

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .