Sample Header Ad - 728x90

How can I find the value of $XDG_CONFIG_HOME, $XDG_CONFIG_HOME, $XDG_STATE_HOME, etc in a Bash script?

3 votes
1 answer
7030 views
This seems like a simple question that every application developer would have, but I can't find the answer. Per the latest [XDG Basedir Spec](https://www.freedesktop.org/wiki/Specifications/basedir-spec/) , there are many directories that should be defined in environment variables. As one example: > There is a single base directory relative to which user-specific configuration files should be written. This directory is defined by the environment variable $XDG_CONFIG_HOME. Let's say my Bash script saves a user config - and I want to follow the XDG spec - How do I find $XDG_CONFIG_HOME? It makes sense that you would do something like
#!/bin/bash

# Print out $XDG_CONFIG_HOME
echo Your XDG_CONFIG_HOME is: [$XDG_CONFIG_HOME]
But running this on a fresh Ubuntu and Fedora Silverblue install both give the output:
$ ./test.sh
Your XDG_CONFIG_HOME is: []
Which seems totally useless, since that would mean on fresh desktop installs of Ubuntu and Fedora Silverblue, my app would write config files into the running directory. Yet, I can see so many applications properly putting the data in ~/.config/. Where are these apps finding the XDG environment variables, and how can I find them too?
Asked by Dr-Bracket (437 rep)
Nov 29, 2022, 01:54 PM
Last activity: Apr 20, 2025, 06:35 PM