How to add exports to fish like in .bashrc?
Solution 1
You can put the user-specific fish configuration, including set directives, in ~/.config/fish/config.fish
. The contents should look more or less like that
set -x PERL5LIB /home/iaco/workspace/perl:/home/iaco/devtools
More information can be found in the documentation.
Solution 2
Use universal variables introduced in fish 2.0.0. -x
means exported, and -U
means that it's declared for every fish session. You can also use the long options --export
and --universal
.
set -xU PERL5LIB /home/iaco/workspace/perl:/home/iaco/devtools
Please note that PATH
variable is a bit of a special case. While PATH
can be universally changed, this will affect your current PATH variable (which may be a bit of a problem if an extra path will be introduced by an operating system). For PATH
variable, use fish_user_paths
variable (which only adds paths) instead. The variable is an array, which means you don't have to put :
characters.
set -U fish_user_paths /home/iaco/workspace/perl/share/bin /home/iaco/bin $fish_user_paths
Related videos on Youtube
codeforester
Scripting and automation enthusiast. Fun fact: Code is the reason for bugs. More code = more bugs! Write reusable code!
Updated on September 18, 2022Comments
-
codeforester over 1 year
I just wanted to be able to add inside some fish configuration file (don't know which/where) the same function as this:
export PERL5LIB=/home/iaco/workspace/perl:/home/iaco/devtools
This line was added inside the .bashrc file and it was able to export the variable each time I opened a terminal.
Is there something like that for fish? I know that I can export variables in fish using the "set" command, but I want to modify one file (don't know which one) in order to automatically add those variables each time I open a fish terminal.
-
Admin about 13 yearsThanks Adam. The main purpose of this change is to be able to include inside the Perl @inc the path of my local libraries. After added the line you suggested, the export was properly made! But, if I run perl -V I won't see the new paths. I know that this is more a Perl question than a fish one, but I just wanted to know if you (or somebody else) have an idea
-
cokeman19 about 13 yearsI should've mentioned the
-x
flag. I've just updated the answer, and you can read more about that in the section "Exporting variables" in the documentation. -
Daniel James over 11 yearsThe main fish site is down, but the documentation from the fishfish fork is at ridiculousfish.com/shell/user_doc/html/commands.html#set (I assume it's the same).
-
grant almost 10 yearsDoes fish have access to environmental variables like $PATH?
-
Scribblemacher almost 5 years@grant yes,
$PATH
etc can be used in fish, including in config.fish.