I'm currently migrating from bash configs over to fish and got stuck translating my over bash exports. It seems there's three ways to do it in Fish that get the job done but I can't tell which one I should use, or if they have side effects I am unaware of
set -g VAR value
set -x VAR value
set -xg VAR valueSurely they do not all do the same thing. Can someone explain what the differences are and in which situations each is appropriate, please?
11 Answer
No, they do not all do the same thing. The -x flag is orthogonal to the -g, -l, and -u flags. The former simply sets the export attribute on the var. The latter three set the scope of the var. You can have a global, unexported, VAR and inside a function do set -lx VAR value to create a locally scoped instance that is exported. When control returns from the function the global scope VAR pops back into existence and it won't be exported.
If you're using a recent version (2.7, maybe 2.6) you can do set --show VAR to display the values in all three scopes and whether or not each one is exported.