Reading the NodeJS page, stumbled upon this bash command:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm


  • Test it ${XDG_CONFIG_HOME-} is empty and prints the home dir Or prints the rest
  • Exports the result
  • executis a script inside the dir

I don't get this ${XDG_CONFIG_HOME-} why is it there for?

I'm also not sure what $(...) is doing here, wouldn't print or echo be enough?

1 Answer 1


XDG_CONFIG_HOME is an environment variable that expands to the directory at which programs should store configuration files. By default, this directory is .config in your home directory. So in my case, it would expand to /home/john/.config.

The command you're asking about seems to check if this environment variable is set. If it is set, it sets NVM_DIR to ${XDG_CONFIG_HOME}/nvm. Otherwise (if XDG_CONFIG_HOME is not set), it sets NVM_DIR to ${HOME}/.nvm. ${HOME} simply expands to your home directory.

I would imagine that NVM_DIR is the directory where this program will store configuration (or other) data. The first line of your command is just choosing where this directory will be, based on if XDG_CONFIG_HOME is set (which it most often is on modern Linux systems, to my knowledge).

  • yes but there is a dash after it. that's my problem Dec 13, 2020 at 17:36

You must log in to answer this question.

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