Skip to content
forked from drone/envsubst

Go package emulates bash environment variable substitution. Also supports Google Secret Manager.

License

Notifications You must be signed in to change notification settings

hguerra/envsubst

 
 

Repository files navigation

envsubst

envsubst is a Go package for expanding variables in a string using ${var} syntax. Includes support for bash string replacement functions. This fork allows you to search Google Secret Manager variables.

Documentation

Documentation can be found on GoDoc.

envsubst -no-empty < input.tmpl > output.txt

Example with Google Secret Manager

file: input.tmpl

Hello ${USER}
My secret from Google: ${gcp:secretmanager:projects/xxx/secrets/mykey/versions/1}

Imposing restrictions

The flags and their restrictions are:

Option Meaning Type Default
-no-empty fail if a variable is set but empty flag false

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}
  • ${var:+default}

About

Go package emulates bash environment variable substitution. Also supports Google Secret Manager.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 98.6%
  • Makefile 1.4%