Version: v0.0.0-...-357881e Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2023 License: BSD-3-Clause Imports: 4 Imported by: 0


Go Reference


Package envutil provides utilities for working with environment variables.



Package envutil provides utilities for working with environment variables.



This section is empty.


This section is empty.


func Dedup

func Dedup(goos string, env []string) []string

Dedup returns a copy of env with any duplicates removed, in favor of later values. Items are expected to be on the normal environment "key=value" form.

Keys are interpreted as if on the given GOOS. (On Windows, key comparison is case-insensitive.)

func Get

func Get(goos string, env []string, key string) string

Get returns the value of key in env, interpreted according to goos.

func Match

func Match(goos, kv, key string) (value string, ok bool)

Match checks whether a "key=value" string matches key and, if so, returns the value.

On Windows, the key comparison is case-insensitive.

func SetDir

func SetDir(cmd *exec.Cmd, dir string)

SetDir sets cmd.Dir to dir, and also updates cmd.Env to ensure that PWD matches.

If dir is the empty string, SetDir clears cmd.Dir and sets PWD to the current working directory.

func SetEnv

func SetEnv(cmd *exec.Cmd, kv ...string)

SetEnv sets cmd.Env to include the given key=value pairs, removing any duplicates for the key and leaving all other keys unchanged.

(Removing duplicates is not strictly necessary with modern versions of the Go standard library, but causes less confusion if cmd.Env is written to a log — as is sometimes done in packages within this module.)

func Split

func Split(kv string) (key, value string)

Split splits a "key=value" string into a key and value.


This section is empty.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL