At my Windows 11 machine, trying to check if the env variable "" exists or no, if yes, I need to read its value, if not there I need to set it, so I wrote the below code:
tmpDir, exists := os.LookupEnv("keyTemp")
fmt.Println("keyTemp: ", exists)
fmt.Println("tmpDir: ", tmpDir)
if !exists {
tmpDir = os.TempDir() + "\\fitz"
fmt.Println("tmpDir: ", tmpDir)
err = os.Setenv("keyTemp", tmpDir)
if err != nil {
panic(err)
}
}
But always (after rerunning the binary) I'm getting the "exists" value as false
and my env variable is never created!