I would like to create the variable $EIGEN
to save the path where I installed the Eigen library in order to link in with my compiler. For this I was using set EIGEN path/to/eigen
However if I echo $EIGEN
in another shell there is no output.
If you want a variable to be set for every shell launched then you should edit the default profile.
By default that file is located at ~/.config/fish/config.fish
, where ~
is your user home directory. If you do not have that file then you should create it. In that file you can enter the same command you used to set the $EIGEN
value in your normal shell.
You can find more at Fish Shell FAQ
If you need to set the value for every program then you should consult the documentation for your operating system which should tell you how to set environment variables globally.
Short answer:
set -Ux EIGEN /path/to/eigen
Explanation:
One of the differentiating features of Fish is the ability to set a "Universal Variable" that is:
The -U
creates a universal variable, with the -x
marking it as exported.
Note that if you already have set $EIGEN
in another shell instance, that "local" or "global" variable will override the universal one.
Here's a pathologic, over-simplified example:
> set EIGEN /bad/path/to/eigen
> set -Ux EIGEN /correct/path/to/eigen
> set --show EIGEN
> echo $EIGEN
/bad/path/to/eigen
> set --show EIGEN
set: Universal variable 'EIGEN' is shadowed by the global variable of the same name.
$EIGEN: set in global scope, unexported, with 1 elements
$EIGEN[1]: |/bad/path/to/eigen|
$EIGEN: set in universal scope, exported, with 1 elements
$EIGEN[1]: |/correct/path/to/eigen|
Also, it's not quite clear from your question whether you mean something like this, starting in fish
:
> set EIGEN /path/to/eigen
echo $EIGEN
/path/to/eigen
bash
$ echo $EIGEN
# No output
That wouldn't even require a universal variable, just an exported one. By default (in most any Linux/Unix shell), variables are set only for the current shell. New processes created from that shell don't see the variable. To make it available to subshells and other launched processes, it needs to be marked as exported. I'm going to switch to bash
here as an example since we already demonstrated above how to mark it exported in fish
. As above, I'll use $
to represent the Bash prompt and >
to represent Fish:
$ EIGEN=/path/to/eigen
$ fish
> echo $EIGEN
> exit
$ echo $EIGEN
/path/to/eigen
$ export EIGEN
$ fish
> echo $EIGEN
/path/to/eigen
set -g
.
Commented
Sep 5, 2021 at 1:59
fish
shell instance and have it take effect in another'fish
shell, or if you mean that you want to have it take effect in abash
(or other) shell.