shellfish

How to set environment variables in fish shell


Can someone please tell me what's the correct way to set a bunch of environment variables in the fish shell?

In my ~/.config/fish/config.fish file, I have a function to setup my environment variables like so:

function setTESTENV
      set -x BROKER_IP '10.14.16.216'
      set -x USERNAME 'foo'
      set -x USERPASS 'bar'
end 

When I type from the command prompt setTESTENV and do a env in the command line, I don't see this information.


Solution

  • The variables you are declaring are keep in a local scope inside your function.

    Use:

    set -g -x
    

    Here "g" is for global.