📅 2015-Jul-31 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ environment variables, fish ⬩ 📚 Archive
Environment variables can be set just like any other variable in the Fish shell.
~/.config/fish/config.fish
:set -x FOO_ENV_VAR /home/joe/bin/some_foo_dir
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 ~/.bashrc
as:
export FOO_ENV_VAR=/home/joe/bin/some_foo_dir:/usr/local/foo_dir
PATH
:set -x PATH /home/joe/bin/some_foo_dir $PATH
Three special environment variables: PATH
, CDPATH
and MANPATH
are 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.cpp
here. 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.so
that is used to load up DLLs when a binary executes requires LD_LIBRARY_PATH
environment 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