How to fetch all environment variables in Go

1 Answer

0 votes
package main
 
import (
  "os"
  "fmt" 
  "strings" 
)
 
func main() {   
    for _, element := range os.Environ() {
        variable := strings.Split(element, "=")
        fmt.Println(variable[0], "-", variable[1])        
    }
}



/*
run:

ISCOBOL_JRE_ROOT - /lib/jvm/java-11-openjdk
SHELL - /bin/bash
ISCOBOL_JDK_ROOT - /lib/jvm/java-11-openjdk
HOSTNAME - abc
PWD - /home
HOME - /root
LANG - en_US.UTF-8
SHLVL - 0
ISCOBOL - /opt/isCOBOL2019R1
LD_LIBRARY_PATH - /opt/isCOBOL2019R1/native/lib
PATH - /usr/local/sbin:...
_ - /usr/bin/time

*/

 



answered Aug 24, 2020 by avibootz
edited Apr 24, 2021 by avibootz

Related questions

2 answers 138 views
2 answers 175 views
175 views asked May 4, 2021 by avibootz
1 answer 139 views
1 answer 156 views
156 views asked Jan 13, 2017 by avibootz
...