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 examp…


This content originally appeared on DEV Community and was authored by Michael Crump

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

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

echo $EMAIL

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

import os
print(os.environ['HOME'])

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

var value = Environment.GetEnvironmentVariable("EMAIL");
Console.WriteLine(value);

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


This content originally appeared on DEV Community and was authored by Michael Crump


Print Share Comment Cite Upload Translate Updates
APA

Michael Crump | Sciencx (2021-04-22T17:37:43+00:00) How to share environment variables in Linux across Bash, Python, .NET and more.. Retrieved from https://www.scien.cx/2021/04/22/how-to-share-environment-variables-in-linux-across-bash-python-net-and-more/

MLA
" » How to share environment variables in Linux across Bash, Python, .NET and more.." Michael Crump | Sciencx - Thursday April 22, 2021, https://www.scien.cx/2021/04/22/how-to-share-environment-variables-in-linux-across-bash-python-net-and-more/
HARVARD
Michael Crump | Sciencx Thursday April 22, 2021 » How to share environment variables in Linux across Bash, Python, .NET and more.., viewed ,<https://www.scien.cx/2021/04/22/how-to-share-environment-variables-in-linux-across-bash-python-net-and-more/>
VANCOUVER
Michael Crump | Sciencx - » How to share environment variables in Linux across Bash, Python, .NET and more.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/22/how-to-share-environment-variables-in-linux-across-bash-python-net-and-more/
CHICAGO
" » How to share environment variables in Linux across Bash, Python, .NET and more.." Michael Crump | Sciencx - Accessed . https://www.scien.cx/2021/04/22/how-to-share-environment-variables-in-linux-across-bash-python-net-and-more/
IEEE
" » How to share environment variables in Linux across Bash, Python, .NET and more.." Michael Crump | Sciencx [Online]. Available: https://www.scien.cx/2021/04/22/how-to-share-environment-variables-in-linux-across-bash-python-net-and-more/. [Accessed: ]
rf:citation
» How to share environment variables in Linux across Bash, Python, .NET and more. | Michael Crump | Sciencx | https://www.scien.cx/2021/04/22/how-to-share-environment-variables-in-linux-across-bash-python-net-and-more/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.