英文:
GO: {GOOS} and {GOARCH} not recognised in environment
问题
我想将我的目录更改为go/pkg/darwin_amd64
,但是$ cd $GOPATH/pkg/${GOOS}_${GOARCH}
无法找到该文件夹,尽管目录存在。
$ echo $GOPATH/pkg/${GOOS}_${GOARCH}
输出的是/go/pkg/_
而不是/go/pkg/darwin_amd64
。
$ go env
命令输出的内容如下:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/sahilkapoor/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
我们可以看到这里定义了GOOS
和GOARCH
。我正在使用Mac OSX 10.10.3上的终端。我漏掉了什么?
英文:
I want to change my diretory to go/pkg/darwin_amd64
but $ cd $GOPATH/pkg/${GOOS}_${GOARCH}
doesn't find the folder though directory exists.
$ echo $GOPATH/pkg/${GOOS}_${GOARCH}
gives /go/pkg/_
instead of /go/pkg/darwin_amd64
.
$ go env
prints:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/sahilkapoor/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
We can see that GOOS
and GOARCH
are defined here. I am using terminal on Mac OSX 10.10.3. What am I missing?
答案1
得分: 4
$GOOS
和$GOARCH
只有在你导出它们到你的shell环境中时才会被定义(除非你正在进行交叉编译,否则这种情况不太可能发生)。
当你运行go env
时,如果这些变量没有被你的环境覆盖,将显示默认值。你应该将你的命令修改为以下形式以获得所需的结果:
cd $(go env GOPATH)/pkg/$(go env GOOS)_$(go env GOARCH)
英文:
$GOOS
and $GOARCH
will only be defined in your shell if you have exported them (which, unless you are doing cross compilation, is unlikely).
When you run go env
, default values are shown when they have not been overwritten by your environment. You should change your command to the following to get the desired results:
cd $(go env GOPATH)/pkg/$(go env GOOS)_$(go env GOARCH)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论