Standard library / os
os.LookupEnv()
Returns the environment value and whether the key exists, including an explicitly empty value. Example intended for Linux/AMD64 with Go 1.23.2 in a disposable working directory; other platforms may differ. Expected stdout: '"" true\n'.
Formal Syntax & Structure
go syntaxgo
func LookupEnv(key string) (string, bool)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| key | string | Environment variable name. |
Return Value
(string, bool)
Returns the environment value and whether the key exists, including an explicitly empty value.
Working Example
Example Snippetgo
package main
import ( "fmt" "os")
func must(e error) { if e != nil { panic(e) }}func main() { must(os.Setenv("BYTEMIND_SAMPLE", "")) v, ok := os.LookupEnv("BYTEMIND_SAMPLE") fmt.Printf("%q %t\n", v, ok)}