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.4.0/muenvsubst -Lo /usr/local/bin/muenvsubst
sudo chmod +x /usr/local/bin/muenvsubst
Substitutes environment variables using Inja templating engine, as envsubst
does.
USAGE: ./muenvsubst [ -h, --help <arg> ] [ -i, --in <arg> ] [ -o,
--out <arg> ] [ -v, --version ]
OPTIONAL:
-h, --help <arg> Print this help.
-i, --in <arg> Input file
-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
- varToBool - convert variable value to boolean
echo "Hello, {{ USER }}!" | muenvsubst
then output will be:
Hello, John!
muenvsubst <<EOF
{%- set username = upper(USER) -%}
Hello, {{ username }}!
EOF
then 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
EOF
then output will be:
Goodbye, John!
USERS="John,Mark,Peter" muenvsubst << EOF
{%- for user in split(USERS,",") -%}
Hello, {{ user }}!
{%- endfor -%}
EOF
then output will be:
Hello, John!
Hello, Mark!
Hello, Peter!