Skip to content

Latest commit

 

History

History
36 lines (29 loc) · 568 Bytes

how-to-get-all-environment-variables.md

File metadata and controls

36 lines (29 loc) · 568 Bytes

How to get all environment variables

package main
import "os"

func main() {
  for _, env := range os.Environ() {
    print(env, "\n")
  }
}
  • os.Environ() - returns list of all environment variables
  • for _, env := range os.Environ() - iterate over all environment variables
  • import "os" - import os module to work with environment variables

group: env

Example:

package main
import "os"

func main() {
  for _, env := range os.Environ() {
    print(env, "\n")
  }
}
USER=www-data
HOME=/var/www
PWD=/tmp