# envsubst: The simplest bash variable substitution tool

🧐 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗲𝗻𝘃𝘀𝘂𝗯𝘀𝘁?  
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

👨‍💻 𝗖𝗼𝗱𝗲:

```bash
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.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1750256904060/76deb445-bbd8-46b2-a57c-2a37e80b6617.gif align="center")
