add example of how to set default variable values

Closes #12720
This commit is contained in:
PowerUser64
2026-05-06 19:16:48 -07:00
committed by Johannes Altmanninger
parent 01b9fd9e31
commit 51ab1f5d35
3 changed files with 12 additions and 0 deletions

View File

@@ -99,6 +99,15 @@ See :ref:`Shell variables <variables>` for more.
.. _bash-globs:
Variable defaults (``${my_variable:-"default value"}``)
-------------------------------------------------------
Fish doesn't have ``${my_variable:-fallback}`` for providing default values to unset variables. Instead, you can set default values by checking whether the variable has been set yet::
# Ensure XDG_CONFIG_HOME is set or use a default value
set -q XDG_CONFIG_HOME || set XDG_CONFIG_HOME $HOME/.config
# now use XDG_CONFIG_HOME as normal
Wildcards (globs)
-----------------

View File

@@ -157,6 +157,8 @@ function __fish_help_describe -a help_item
return
case fish_for_bash_users#test-test
return
case fish_for_bash_users#variable-defaults-my-variable-default-value
return
case fish_for_bash_users#variables
return
case fish_for_bash_users#wildcards-globs

View File

@@ -194,6 +194,7 @@ fish_for_bash_users#special-variables
fish_for_bash_users#string-manipulation
fish_for_bash_users#subshells
fish_for_bash_users#test-test
fish_for_bash_users#variable-defaults-my-variable-default-value
fish_for_bash_users#variables
fish_for_bash_users#wildcards-globs
index