Creating environment variables is useful for when you want to use the same variable across multiple languages, or perhaps to maintain a consistent environment for your settings on your machine, such as development credentials.

First create your environment variable in windows by doing the following:

  • Edit the environment variables for your account.

Environment Variables

  • Create a new environment variable and give it a value.

Environment Variables

Bash

To access and print the variable in bash from the command-line:

echo %MY_VARIABLE%

Powershell

To access and print the variable in Powershell:

Write-Output([System.Environment]::GetEnvironmentVariable('MY_VARIABLE'))

Python

To access and print the variable in python:

import os
print(os.environ.get('MY_VARIABLE'))

C#

To access and print the variable in C#:

Console.WriteLine(System.Environment.GetEnvironmentVariable("MY_VARIABLE"));