Substitutes environment variables using one of the templating engines, as envsubst does, but using a powerfull templating engine.
This is a list of supported template engines:
inja- Inja templates
One of the advantages of this utility is that it is built very small static binary without any dependencies. Architecture of binary is Linux x86 (32 bit). It can be run in any Linux x86 and x86_64, both new and very old versions.
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.5.0/muenvsubst -Lo /usr/local/bin/muenvsubst
sudo chmod +x /usr/local/bin/muenvsubstSubstitutes environment variables using Inja templating engine, as envsubst
does.
USAGE: ./muenvsubst [ -h, --help <arg> ] [ -i, --in <arg> ] [ -d,
--include-dir <arg> ] [ -o, --out <arg> ] [ -v, --version ]
OPTIONAL:
-h, --help <arg> Print this help.
-i, --in <arg> Input file
-d, --include-dir <arg> The directory where the included files are searched
for. This argument can be specified more than once.
-o, --out <arg> Output file
-v, --version Output version information and exit
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.
Also supported function pipe calling syntax. These are equal expressions:
{{ split("A,B,C", ",") }}
{{ "A,B,C" | split(",") }}
{{ sh("198c126c-2691-463f-9708-1ee485ce4d68", "sed 's/-//g'") }}
{{ "198c126c-2691-463f-9708-1ee485ce4d68" | sh("sed 's/-//g'") }}
- error - throws an error
- fromBase64 - decode base64 string
- fromJson - parse JSON string to object
- sh - execute shell script
- split - splits text by delimiter
- toBase64 - encode base64 string
- toBool - convert any value to boolean
- toJson - serialize value to JSON string
- trim - trims text
echo "Hello, {{ USER }}!" | muenvsubstthen output will be:
Hello, John!
muenvsubst <<EOF
{%- set username = upper(USER) -%}
Hello, {{ username }}!
EOFthen output will be:
Hello, JOHN!
USE_GREETER=no USE_GOODBYER=yes muenvsubst << EOF
## if USE_GREETER=="yes"
Hello, {{ USER }}!
## endif
## if USE_GOODBYER=="yes"
Goodbye, {{ USER }}!
## endif
EOFthen output will be:
Goodbye, John!
muenvsubst << EOF
## if default(USE_GREETER, null) | toBool
Hello, {{ USER }}!
## endif
EOFUSERS="John,Mark,Peter" muenvsubst << EOF
{%- for user in split(USERS,",") -%}
Hello, {{ user }}!
{%- endfor -%}
EOFthen output will be:
Hello, John!
Hello, Mark!
Hello, Peter!
Content of greeter.j2 file:
Hello, {{ USER }}!
Render template:
muenvsubst << EOF
## include "greeter.j2"
EOFthen output will be:
Hello, John!