envsubst

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2025 License: Apache-2.0 Imports: 10 Imported by: 3

README

envsubst

github.com/fluxcd/pkg/envsubst is a Go package for expanding variables in a string using ${var} syntax. Includes support for bash string replacement functions.

This package is a fork of drone/envsubst.

Supported Functions

Expression Meaning
${var} Value of $var
${#var} String length of $var
${var^} Uppercase first character of $var
${var^^} Uppercase all characters in $var
${var,} Lowercase first character of $var
${var,,} Lowercase all characters in $var
${var:n} Offset $var n characters from start
${var:n:len} Offset $var n characters with max length of len
${var#pattern} Strip shortest pattern match from start
${var##pattern} Strip longest pattern match from start
${var%pattern} Strip shortest pattern match from end
${var%%pattern} Strip longest pattern match from end
${var-default} If $var is not set, evaluate expression as $default
${var:-default} If $var is not set or is empty, evaluate expression as $default
${var=default} If $var is not set, evaluate expression as $default
${var:=default} If $var is not set or is empty, evaluate expression as $default
${var/pattern/replacement} Replace as few pattern matches as possible with replacement
${var//pattern/replacement} Replace as many pattern matches as possible with replacement
${var/#pattern/replacement} Replace pattern match with replacement from $var start
${var/%pattern/replacement} Replace pattern match with replacement from $var end

For a deeper reference, see bash-hackers or gnu pattern matching.

Unsupported Functions

  • ${var+default}
  • ${var:?default}
  • ${var:+default}

Documentation

Overview

Package envsubst is a Go package for expanding variables in a string using `${var}` syntax. Includes support for bash string replacement functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Eval

func Eval(s string, mapping func(string) (string, bool)) (string, error)

Eval replaces ${var} in the string based on the mapping function.

func EvalEnv

func EvalEnv(s string, strict bool) (string, error)

EvalEnv replaces ${var} in the string according to the values of the current environment variables. References to undefined variables are replaced by the empty string.

func Getenv

func Getenv(s string) (string, bool)

Types

type Template

type Template struct {
	// contains filtered or unexported fields
}

Template is the representation of a parsed shell format string.

func Parse

func Parse(s string) (t *Template, err error)

Parse creates a new shell format template and parses the template definition from string s.

func ParseFile

func ParseFile(path string) (*Template, error)

ParseFile creates a new shell format template and parses the template definition from the named file.

func (*Template) Execute

func (t *Template) Execute(mapping func(string) (string, bool)) (str string, err error)

Execute applies a parsed template to the specified data mapping.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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