Skip to content

Instantly share code, notes, and snippets.

@nickmccurdy
Created March 13, 2014 00:22
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickmccurdy/9519543 to your computer and use it in GitHub Desktop.
Save nickmccurdy/9519543 to your computer and use it in GitHub Desktop.
List all environment variables in Go
package main
import (
"os"
"fmt"
)
func main() {
for _, pair := range os.Environ() {
fmt.Println(pair)
}
}
@avnish30jn
Copy link

This doesn't list all the environment variables. Only the env variables that are exported in that session are listed. Is there any way to list all the environment variables ?

@coolaj86
Copy link

@avnish30jn A process is "firewalled" from its parents and siblings. One process can have the same variable with a completely different value as another. A process only has access to its own envs (and the ones the parent exports). Were it not so, scripting would be... hell, in the worst way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment