-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenviron01.go
More file actions
32 lines (24 loc) · 741 Bytes
/
environ01.go
File metadata and controls
32 lines (24 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* Alta3 Research | RZFeeser
Environmental Variables - Setting and reading environmental variables
from an environment */
package main
import (
"fmt"
"os"
"strings"
)
func main() {
// set the environmental variable "ALTA" to "3"
os.Setenv("ALTA", "3")
fmt.Println("ALTA:", os.Getenv("ALTA"))
// we did not set this value
fmt.Println("RESEARCH:", os.Getenv("RESEARCH"))
// print a blank line
fmt.Println()
// loop across all of the environmental variables on the system
// throw out the positions and only take the value
for _, e := range os.Environ() {
pair := strings.SplitN(e, "=", 2) // split "e" across the "="
fmt.Println(pair[0])
}
}