Search code examples
bashenvironment-variablesfish

How can I specify PATH env var in fish shell in a declarative command


I want my $PATH environment variable to specifically contain 3 specific directories and nothing else.

I don't want to use individual ADD and REMOVE commands to shape my $PATH variable.

In Bash I can just say PATH="aaa:bbb:ccc"

But I haven't found a way to do that in fish shell. OR I'm missing some syntax.

The Fish tutorial also doesn't cover this. It only mentions iterative approaches (add/remove from path)

What command can I add to my ~/.config/fish/config.fish to accomplish this?


Solution

  • You can use the set with the -gx together because it is a shorthand to define a global variable and export it to the environment in a single command, so for example you can save it into this path ~/.config/fish/config.fish

    set -gx PATH "/path/to/test1" "/path/to/test2" "/path/to/test3"
    

    don't forget to restart your shell or run source ~/.config/fish/config.fish for the changes to take effect!