DEV Community

Cover image for How to share environment variables in Linux across Bash, Python, .NET and more.
Michael Crump
Michael Crump

Posted on

5 2

How to share environment variables in Linux across Bash, Python, .NET and more.

Hello everyone,

The export command in Linux is used to set Environment variables, but you may not be aware that you can use the variables in other programming languages to prevent secrets from leaking in GitHub commits, etc.

Take the following example:

You've set an environment variable such as:

export EMAIL=youremail@domain.com
Enter fullscreen mode Exit fullscreen mode

On your terminal prompt, you can check to ensure this variable works by running:

echo $EMAIL
Enter fullscreen mode Exit fullscreen mode

You can also take that same environment variable and make it accessible in Python with:

import os
print(os.environ['HOME'])
Enter fullscreen mode Exit fullscreen mode

on the flip side, you can do the same thing with .NET

var value = Environment.GetEnvironmentVariable("EMAIL");
Console.WriteLine(value);
Enter fullscreen mode Exit fullscreen mode

Pretty neat, huh?

You can also checkout the video that I made showing this off in action before trying it on your own:

Video (5 mins)

Conclusion

Feel free to checkout my Twitch streams as we learn about security and app development or you can watch the condensed version of all of my streams by subscribing to my YouTube.

Stay connected with me on social platforms for daily software development news.

-Twitter | Twitch | Instagram | YouTube | GitHub | Website

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Dive into this insightful write-up, celebrated within the collaborative DEV Community. Developers at any stage are invited to contribute and elevate our shared skills.

A simple "thank you" can boost someone’s spirits—leave your kudos in the comments!

On DEV, exchanging ideas fuels progress and deepens our connections. If this post helped you, a brief note of thanks goes a long way.

Okay