5

For those of you who have no idea what Fish is: http://fishshell.com/

Similarly, if you are not familiar with a Go coding environment and still wish to try and figure out this small puzzle, here is some info: http://golang.org/doc/code.html

Anyway, so I'm trying to set up a Go-lang dev. environment on a new machine where I'm giving Fish a try.

So I have $GOPATH set to /home/<me>/workspace/go-workspace in both bash and fish. This means that the go tool expects a bin, pkg, and src directory beneath that. Which is there.

However, typing go get while in a directory with some code (which would normally download it's dependencies) yields

package code.google.com/p/go.crypto/openpgp: cannot download, $GOPATH not set. For more details see: go help gopath
package code.google.com/p/go.crypto/openpgp/armor: cannot download, $GOPATH not set. For more details see: go help gopath
package code.google.com/p/go.crypto/ssh: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/codegangsta/cli: cannot download, $GOPATH not set. For more details see: go help gopath
package github.com/oleiade/reflections: cannot download, $GOPATH not set. For more details see: go help gopath
package launchpad.net/goamz/aws: cannot download, $GOPATH not set. For more details see: go help gopath
package launchpad.net/goamz/s3: cannot download, $GOPATH not set. For more details see: go help gopath

I know this to be absolutely false because I can run echo $GOPATH and out pops the value I have set.

Then, strangely, if I run the same command in bash with the same $GOPATH set, it just works.

Can anyone tell me why?

Or, more generally, can you tell me why a program would detect an environment variable in one shell but not another?

2 Answers 2

10

Did you remember to mark $GOPATH in fish as exported?

set -x GOPATH /home/<me>/workspace/go-workspace

It's not sufficient to test with

echo $GOPATH

since that will work regardless of whether the variable is exported. Check with

bash -c 'echo $GOPATH'

which will only print the value of GOPATH if it has been exported. In bash, you export variables like this:

export GOPATH=/home/<me>/workspace/go-workspace
2
  • I do believe the -x was what I was missing. D'oh.
    – Logan
    Nov 22, 2013 at 5:21
  • This worked for me, thanks, but I had to use the -g modifier, as in set -gx GOPATH <whatever>
    – agam
    May 16, 2016 at 6:06
1

Not all shell variables are environment variables. In bash, you'd have to export a variable for it to become an environment variable in child processes (if that variable wasn't already an environment variable). That is, assuming FOO is not defined already, then simply executing FOO=bar would not cause variable FOO to be visible in the environment of a child process. You'd have to follow that up with export FOO, or you could do it all at once by doing export FOO=bar.

I would assume something similar is going on in fish, where you must have GOPATH defined simply as a shell variable, and not as a shell variable also exported into the environment.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .