Go package emulates bash environment variable substitution
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
liuzhiguo 8805562e2d 更改包名 5 months ago
cmd/envsubst 更改包名 5 months ago
parse Handle different escape characters 3 years ago
path added missing path file 6 years ago
.drone.yml update yaml 5 years ago
.gitignore add envsubst cli command 5 years ago
LICENSE Initial commit 7 years ago
eval.go fix package name 7 years ago
eval_test.go Handle different escape characters 3 years ago
funcs.go 更改包名 5 months ago
funcs_test.go Merge pull request #20 from car409/master 3 years ago
go.mod 更改包名 5 months ago
go.sum 更新包名 5 months ago
readme.md (maint) cleanup docs 3 years ago
template.go 更改包名 5 months ago

readme.md

envsubst

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

Documentation

Documentation can be found on GoDoc.

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}