Difference between set -g and set -x

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 value

Surely they do not all do the same thing. Can someone explain what the differences are and in which situations each is appropriate, please?

1

1 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.

5

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like