The syntax you are using for setting environment variables is correct, but the fact that you are setting them as part of a function and later calling that function by hand is what prevents your environment variables from being exposed to other programs such as env
because as @j-- mentioned the local scope of your environment variables is then limited to that function.
If you instead define the environment variables directly in ~/.config/fish/config.fish
without using a function, they get applied to every fish terminal session you open and to all programs you run from them:
# ~/.config/fish/config.fish
set -x BROKER_IP '10.14.16.216'
set -x USERNAME 'foo'
set -x USERPASS 'bar'
And it similarly works if you define them in a function and call that function in ~/.config/fish/config.fish
:
# ~/.config/fish/config.fish
function setTESTENV
set -x BROKER_IP '10.14.16.216'
set -x USERNAME 'foo'
set -x USERPASS 'bar'
setTESTENV
That function can also be in a separate fish script in ~/.config/fish/functions
, which can help you keep your config.fish
file organized if you need to set a lot of different environment variables.