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/html_node/envsubst-Invocation.html>.

Install

All systems
curl cmd.cat/envsubst.sh
Debian Debian
apt-get install gettext-base
Ubuntu
apt-get install gettext-base
Alpine
apk add gettext
Arch Arch Linux
pacman -S gettext
image/svg+xml Kali Linux
apt-get install gettext-base
CentOS
yum install gettext
Fedora
dnf install gettext
Windows (WSL2)
sudo apt-get update sudo apt-get install gettext-base
OS X
brew install gettext
Raspbian
apt-get install gettext-base
Docker
docker run cmd.cat/envsubst envsubst powered by Commando

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/html_node/envsubst-Invocation.html>.

  • 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 '$USER $SHELL $HOME' < path/to/input_file

© tl;dr; authors and contributors