Substitutes environment variables using one of the templating engines, as envsubst does.
This is a list of supported template engines:
mstch- Mustache templatesinja- Inja templates
One of the advantages of this utility is that it is built in a small static binary without any dependencies. Architecture of binary is Linux x86 (32 bit). It can be run in docker from scratch.
Download and copy binary to any destination specified in PATH (~/bin, /usr/local/bin, /usr/bin).
Do not forget to set execution flag on binary with chmod.
sudo curl https://github.com/navrocky/muenvsubst/releases/download/1.2.0/muenvsubst -Lo /usr/local/bin/muenvsubst
sudo chmod +x /usr/local/bin/muenvsubstSubstitutes environment variables using one of the templating engines, as
envsubst does.
USAGE: ./muenvsubst [ -e, --engine <arg> ] [ -h, --help <arg> ] [ -V,
--version ]
OPTIONAL:
-e, --engine <arg> Use template engine. Supported engines: mstch, inja.
Default is: inja
-h, --help <arg> Print this help.
-V, --version Output version information and exit
Mstch library fully supports original {{ Mustache }} syntax described here.
Inja inspired by Python's Jinja and supports subset of original Jinja syntax. It much more powerfull then Mustache.
Inja syntax documented here and original Jinja syntax documented here.
Additional functions:
-
Split text by delimiter:
split(text: string, delimiter: string): string -
Throw error:
error(message: string)
Simple variable substitution:
echo "Hello, {{ USER }}!" | muenvsubstthen output will be:
Hello, John!
-
Simple variable substitution:
echo "Hello, {{ USER }}!" | muenvsubst -e inja
then output will be:
Hello, John! -
Using variable and function:
muenvsubst -e inja <<EOF {%- set username = upper(USER) -%} Hello, {{ username }}! EOF
then output will be:
Hello, JOHN! -
Render conditional block:
USE_GREETER=no USE_GOODBYER=yes muenvsubst -e inja << EOF {%- if USE_GREETER=="yes" -%} Hello, {{ USER }}! {%- endif -%} {%- if USE_GOODBYER=="yes" -%} Goodbye, {{ USER }}! {%- endif -%} EOF
then output will be:
Goodbye, John! -
Using split and loop:
USERS="John,Mark,Peter" muenvsubst -e inja << EOF {%- for user in split(USERS,",") -%} Hello, {{ user }}! {%- endfor -%} EOF
then output will be:
Hello, John! Hello, Mark! Hello, Peter!