Environment variables can be set just like any other variable in the Fish shell.
- To export an environment variable to the shell, add it in
set -x FOO_ENV_VAR /home/joe/bin/some_foo_dir
- If this a environment variable with many values, then set it as an array. In Fish, you set an array variable with a space-delimited series of values:
set -x FOO_ENV_VAR /home/joe/bin/some_foo_dir /usr/local/foo_dir
Under Bash, you might have set this same environment variable in
- If the environment variable with many values already exists and you want to prepend or append a value to it, the technique is the same. For example, to prepend to
set -x PATH /home/joe/bin/some_foo_dir $PATH
- Three special environment variables:
MANPATHare treated differently by Fish. These arrive from the environment to Fish as colon-separated, they are converted to array so we can set them easily as shown above using space-delimiter and then they are sent back to the environment as colon-separated. This logic can be seen in the Fish source code file
src/env.cpphere. This is also explained in this issue.
The problem now is that there are many other environment variables which need to be colon-delimited, but Fish does not do that. For example, the dynamic linker
ld.sothat is used to load up DLLs when a binary executes requires
LD_LIBRARY_PATHenvironment variable to be colon-delimited. I got errors when this variable was set using space-delimiters: cannot open shared object file: No such file or directory
If you run into any problems with an environment variable that takes a series of values, then check back to see how it is set in traditional shells like Bash. If it is colon-delimited there, then you might need to make it colon-delimited in Fish too. But, do remember to enclose it in double quotes for variable expansion to work correctly. For example:
set -x FOO_ENV_VAR "/home/joe/bin/some_foo_dir:$FOO_ENV_VAR"
Tried with: Fish 2.2 and Ubuntu 14.04