Pergunta

I am developing on OSX 10.7.4.

I have been experiencing some problems getting the "go get" command to work. In the course of trying to figure out what the problem was, I realized that Go was having trouble reading the $PATH environment variable.

The following script exhibits the problem:-

(PATH is returned as an empty string, and syscall.Getenv returns ok=false)

package main


import (
    "os"
    "syscall"
    "fmt"
)

func main() {

    path := os.Getenv("PATH")
    fmt.Println(path)

    syscall_path, ok := syscall.Getenv("PATH")
    fmt.Println(syscall_path)
    fmt.Println(ok)

}

I cannot imagine that this is a bug, as it is too dramatic to have gone unnoticed. So my question is this: In what way am I being stupid now?

:-)

I.e. What do I need to do to enable Go to access environment variables?

--Update:

As it turns out, it is actually a problem with my shell - Homebrew stopped working also, with the error message:

/usr/local/Library/Homebrew/global.rb:95: private method `split' called for nil:NilClass (NoMethodError)
    from /usr/local/bin/brew:10:in `require'
    from /usr/local/bin/brew:10

I think that the problem stemmed from my use of the fish shell, which does not seem to be setting up the environment as I might have expected.

Foi útil?

Solução

As it turns out, it was a malformed ~/.config/fish/config.fish file that was to blame.

I was using:

set -g VARNAME value

Which instead should be:

set VARNAME value
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top