Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set environment variables in fish shell

Tags:

shell

fish

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.

like image 684
cfpete Avatar asked Sep 02 '14 21:09

cfpete


People also ask

How do you set a variable in a fish shell?

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 .

How do I set environment variables in Bourne shell?

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.

How will you set an environmental variable?

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.

How do you set the PATH on a fish shell?

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.


1 Answers

Use Universal Variables

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.

like image 142
Paolo Moretti Avatar answered Sep 23 '22 11:09

Paolo Moretti