I have this code where I just want to set a environment variable:
package main
import (
"os"
"fmt"
)
func main() {
_ = os.Setenv("FOO", "BAR")
fmt.Println(os.Getenv("FOO"))
}
Running this file:
>$ go run file.go
BAR
The fmt.Println
call prints BAR
correctly, but then I expected this env variable to be set on my session as well, however:
>$ echo $FOO
>$
There's nothing on $FOO
, it is empty. Is this a expected behavior? If so, how can I make this env variable to persist on my session setting it with a go
program like this?