I have an issue with environment variables that I am not able to solve, namely. os.Environ returns a slice of key-value pair, which correctly shows the values I set in the bash shell, however when I try to access them using os.Getenv the method returns null and what’s worse, os.LookupEnv returns ok == true, but the variable is not having any value. What is going on? Any Ideas?
Go 1.13
Default Bash 3.2.57 (Apple edition)
MacOS Mojave 10.14.6
and the only issue I can think of is that something is somewhere cached and it did not propagate throughout the system and I don’t think it’s BASH or Mac.
which correctly corresponds with printenv statement above. This is the code we are talking about (and this also affects Getenv and LookupEnv).
for _, e := range os.Environ() {
fmt.Println(e)
}
and
if username, ok := os.LookupEnv("X_USERNAME"); ok {
Username = username
}
if password, ok := os.LookupEnv("X_PASSWORD"); ok {
Password = password
}
// ...