登录
首页 >  Golang >  Go问答

Fish shell 中未定义GOPATH环境变量?

来源:stackoverflow

时间:2024-03-09 14:42:25 379浏览 收藏

本篇文章给大家分享《Fish shell 中未定义GOPATH环境变量?》,覆盖了Golang的常见基础知识,其实一个语言的全部知识点一篇文章是不可能说完的,但希望通过这些问题,让读者对自己的掌握程度有一定的认识(B 数),从而弥补自己的不足,更好的掌握它。

问题内容

我有一个 ~/.config/fish/config.fish 其中包含以下几行:

set path $path (go env gopath)/bin
set -x gopath (go env gopath)

如果我只是在命令行运行 go env gopath,我会得到默认位置 (~/go):

> go env gopath
/users/kurt/go

但是,$gopath 环境变量未定义:

> echo $GOPATH

为什么 $gopath 环境变量未设置?


解决方案


set -x 只会影响您当前的会话。一旦您注销该会话,导出就会消失。

set --export --global 将在所有正在运行的 fish 会话中导出您的环境,但是它是短暂的,并且在您注销后不会持续存在。

set --export --universal 将在所有正在运行的 fish 会话中导出您的环境,并且是持久的。

-g or --global
       Causes the specified shell variable to be given a global scope. 
Global variables don't disappear and are available to all functions 
running in the same shell.  They can even be modified.

-U or --universal
       Causes  the  specified shell variable to be given a universal scope. 
If this option is supplied, the variable will be shared between all the current 
user's fish instances on the current computer, and will be preserved across 
restarts of the shell

如果您正在运行当前版本的fish,您可以使用内置的fish_add_path (go env gopath)/bin一次就可以了,您不必将其放在conf文件中。

今天关于《Fish shell 中未定义GOPATH环境变量?》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>