HiveBrain v1.2.0
Get Started
← Back to all entries
snippetbashTip

envsubst — Substitutes environment variables with their value in shell format strings. Variables to be replaced

Submitted by: @import:tldr-pages··
0
Viewed 0 times
commandenvsubstclienvironmenttheirwithvariablessubstitutes

Problem

How to use the envsubst command: Substitutes environment variables with their value in shell format strings. Variables to be replaced should be in either ${var} or $var format. More information: <https://www.gnu.org/software/gettext/manual/gettext.html#envsubst-Invocation>.

Solution

envsubst — Substitutes environment variables with their value in shell format strings. Variables to be replaced should be in either ${var} or $var format. More information: <https://www.gnu.org/software/gettext/manual/gettext.html#envsubst-Invocation>.

Replace environment variables in stdin and output to stdout:
echo '{{$HOME}}' | envsubst


Replace environment variables in an input file and output to stdout:
envsubst < {{path/to/input_file}}


Replace environment variables in an input file and output to a file:
envsubst < {{path/to/input_file}} > {{path/to/output_file}}


Replace environment variables in an input file from a space-separated list:
envsubst < {{path/to/input_file}} '{{$USER $SHELL $HOME}}'

Code Snippets

Replace environment variables in `stdin` and output to `stdout`

echo '{{$HOME}}' | envsubst

Replace environment variables in an input file and output to `stdout`

envsubst < {{path/to/input_file}}

Replace environment variables in an input file and output to a file

envsubst < {{path/to/input_file}} > {{path/to/output_file}}

Replace environment variables in an input file from a space-separated list

envsubst < {{path/to/input_file}} '{{$USER $SHELL $HOME}}'

Context

tldr-pages: common/envsubst

Revisions (0)

No revisions yet.