docs: Point away from set -x

This is a common anti-pattern, we should try to get people to do `set -gx`.
This commit is contained in:
Fabian Homborg 2021-02-01 18:12:24 +01:00
parent 97be837ff5
commit 2faf814da4
3 changed files with 7 additions and 4 deletions

View file

@ -10,7 +10,7 @@ How do I set or clear an environment variable?
----------------------------------------------
Use the :ref:`set <cmd-set>` command::
set -x key value
set -x key value # typically set -gx key value
set -e key
Since fish 3.1 you can set an environment variable for just one command using the ``key=value some command`` syntax, like in other shells. The two lines below behave identically - unlike other shells, fish will output ``value`` both times::
@ -18,6 +18,8 @@ Since fish 3.1 you can set an environment variable for just one command using th
key=value echo $key
begin; set -lx key value; echo $key; end
Note that "exported" is not a :ref:`scope <variables-scope>`, but an additional bit of state. A variable can be global and exported or local and exported or even universal and exported. Typically it makes sense to make an exported variable global.
How do I check whether a variable is defined?
---------------------------------------------

View file

@ -1095,7 +1095,7 @@ For example::
set -gx GTK2_RC_FILES "$XDG_CONFIG_HOME/gtk-2.0/gtkrc"
set -gx LESSHISTFILE "-"
It typically makes sense to make exported variables global as well, but local-exported variables can be useful if you need something more specific than :ref:`Overrides <variables-override>`. They are *copied* to functions so the function can't alter them outside, and still available to commands.
Note: Exporting is not a :ref:`scope <variables-scope>`, but an additional state. It typically makes sense to make exported variables global as well, but local-exported variables can be useful if you need something more specific than :ref:`Overrides <variables-override>`. They are *copied* to functions so the function can't alter them outside, and still available to commands.
.. _variables-lists:
@ -2005,10 +2005,9 @@ Examples:
If you want to add the directory ``~/linux/bin`` to your PATH variable when using a login shell, add the following to your ``~/.config/fish/config.fish`` file::
if status --is-login
set -x PATH $PATH ~/linux/bin
set -gx PATH $PATH ~/linux/bin
end
If you want to run a set of commands when fish exits, use an `event handler <#event>`_ that is triggered by the exit of the shell::

View file

@ -294,6 +294,8 @@ It can also be unexported with ``--unexport`` or ``-u``.
This works the other way around as well! If fish is started by something else, it inherits that parents exported variables. So if your terminal emulator starts fish, and it exports ``$LANG`` set to ``en_US.UTF-8``, fish will receive that setting. And whatever started your terminal emulator also gave *it* some variables that it will then pass on unless it specifically decides not to. This is how fish usually receives the values for things like ``$LANG``, ``$PATH`` and ``$TERM``, without you having to specify them again.
Note that exported variables can be local or global or universal - "exported" is not a :ref:`scope <variables-scope>`. Usually you'd make them global via ``set -gx MyVariable SomeValue``.
.. _tut-lists:
Lists