Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to list environment variables used by program

📅 2018-Apr-20 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ environment variables, ltrace ⬩ 📚 Archive

Problem

Many programs fail or behave mysteriously because they are looking for or reading environment variables that you may not be aware of. It would be very useful if you could see what environment variables they are probing for.

Solution

If the program is using the getenv standard library call, then you can list all those calls, the environment variable requested for and what value was returned using ltrace:

$ ltrace -e getenv ./your_program

You will be surprised how many environment variables you had no idea about are probed by common programs that you use. I find this usage to be immensely useful in increasing my understanding of any program I use.


© 2023 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 Mastodon📧 Email