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 these information.
To give a variable to an external command, it needs to be “exported”. Unlike other shells, fish does not have an export command. Instead, a variable is exported via an option to set , either --export or just -x .
In the Bourne and Korn shells, you can use the uppercase variable name equal to some value to set both shell and environment variables. You also have to use the export command to activate the variables for any subsequently executed commands.
On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables. Click New to create a new environment variable.
Use a universal fish_user_paths - this is the default if it doesn't already exist. Manipulate PATH directly. Move already-existing components to the place they would be added - by default they would be left in place and not added again. Print the set command used.
If the variable has to be shared between all the current user Fish instances on the current computer and preserved across restarts of the shell you can set them using -U
or --universal
. For example:
set -Ux FOO bar
Using set
with -g
or --global
doesn't set the variable persistently between shell instances.
Note:
Do not append to universal variables in config.fish
file, because these variables will then get longer with each new shell instance. Instead, simply run set -Ux
once at the command line.
Universal variables will be stored in the file ~/.config/fish/fish_variables
as of Fish 3.0. In prior releases, it was ~/.config/fish/fishd.MACHINE_ID
, where MACHINE_ID was typically the MAC address.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With