import "github.com.hyperhq.hyper.engine.Env" // set a new environment variable Env.Set("MY_VAR", "my value") // retrieve the value of an environment variable val := Env.Get("MY_VAR") fmt.Println(val) // Output: my value // check if an environment variable exists exists := Env.Exists("MY_VAR") fmt.Println(exists) // Output: true // remove an environment variable Env.Unset("MY_VAR") // check again if the environment variable is still there exists = Env.Exists("MY_VAR") fmt.Println(exists) // Output: false
import ( "github.com.hyperhq.hyper.engine.Env" "os" ) // get the value of the "PATH" environment variable path := Env.Get("PATH") // append a new directory to the PATH newPath := path + ":/usr/local/bin" os.Setenv("PATH", newPath) // verify that the new directory is now in the PATH updatedPath := Env.Get("PATH") fmt.Println(updatedPath)This example demonstrates how to manipulate the values of existing environment variables, using the `Setenv()` function from the standard library. It shows how to get the current value of an environment variable, modify it, and then set the modified value back to the environment for the current process.