how to set environment variables in fish shell

牧云@^-^@ 提交于 2019-12-02 17:22:33

The variables you are declaring are keep in a local scope inside your function.

Use:

set -g -x

Here "g" is for global.

Paolo Moretti

Use Universal Variables

If the variable has to be shared between all the current user fish instances on the current computer and preserved across restarts of the shell you have to use -U or --universal:

set -Ux FOO bar

Using set with -g or --global doesn't set the variable persistently between shell instances

Environment Variables in Fish

I would like to add that, while @JosEduSol's answer is not incorrect and does help solve the OP problem, -g is only setting the scope to be global, while -x is causing the specified environment variable to be exported to child processes.

The reason the above fails, is because @cfpete is setting the env vars inside a function and the default scope will be local to that function.

another option is to run:

export (cat env_file.txt |xargs -L 1)

where env_file.txt contains rows of the format VAR=VALUE

this has the benefit of keeping the variables in a format supported by other shells and tools

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!