envsubst: The simplest bash variable substitution tool

I'm a curious Geek with an insatiable thirst to learn new technologies and enjoy the process every day. I aim to deliver high-quality services with the highest standards and cutting-edge DevOps technologies to make people's lives easier.
๐ง ๐ช๐ต๐ฎ๐ ๐ถ๐ ๐ฒ๐ป๐๐๐๐ฏ๐๐?
envsubst (GNU gettext) streams stdin โ stdout, replacing any $VAR with their environment values. Think sed for env-vars, no regex.
๐ ๐ช๐ต๐ฒ๐ป ๐ฑ๐ผ๐ฒ๐ ๐ถ๐ ๐๐ต๐ถ๐ป๐ฒ?
โข Container start-up configs: inject secrets or hostnames into nginx.conf
โข Quick local scripting: stamp todayโs date or $HOME into a file in 2 lines
โข CI/CD pipelines: render YAML/INI/JSON per-environment without Helm/Jinja
๐จโ๐ป ๐๐ผ๐ฑ๐ฒ:
export IP=$(curl -s https://api.ipify.org)
envsubst '$IP' < hostname.tmpl > hostname.conf
โน๏ธ ๐๐ ๐ฝ๐น๐ฎ๐ป๐ฎ๐๐ถ๐ผ๐ป:
1๏ธโฃ curl fetches my public IP address and stores it in the IP environment variable.
2๏ธโฃ envsubst reads the template file, replaces every instance of $IP with that value, and saves the finished file as hostname.conf.
๐๏ธ Check the 14-second demo below to watch it happen in real time.


![Up and Running with kubectl-ai [PDF]](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1753898584930%2F01739f18-1331-4d48-b709-fc2750685607.png&w=3840&q=75)
![How to deal with DNS caches [PDF]](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1753101148740%2F9721c8d4-86d5-4ec8-b4f7-c317f7ccfe56.png&w=3840&q=75)
![Are Kubernetes Secrets Really Secure? [PDF]](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1752308392314%2F25995822-24ef-4fab-afa4-f88a806d9e89.png&w=3840&q=75)
