# Setting environment variables

An environment variable is a variable set outside of a program: it is then available to shell commands, Python or R scripts, etc. The benefit of using such variables is that they allow the same code to work in different environments: if BLab share is mounted to Z:\ on one machine, Y:\ on another, and `/Volumes/Fas-Phyc-PEB-Lab` on yet another one, a program can use the value of the `BLAB_SHARE_PATH` environment variable set on each machine to Z:\\, Y:\\, and /Volumes/Fas-Phyc-PEB-Lab respectively.

## On MacOS

The instructions will depend on which shell you are using (run `ps -p $$` and look at the CMD column in the output if unsure). For bash, edit `~/.bash_profile`, for zsh, edit `~/.zprofile`. In both cases, add the following line to set `BLAB_SHARE_PATH` to `/Volumes/Fas-Phyc-PEB-Lab`

```
export BLAB_SHARE_PATH=/Volumes/Fas-Phyc-PEB-Lab
```

## On Windows

1. Click on the Start button.
2. Start typing "environment".
3. Select "Edit environment variables for your account" (or something similar, just not something with "the system").
4. Click "New"/"Add".
5. To set `BLAB_SHARE_PATH` to `Z:\`, use `BLAB_SHARE_PATH` as the name and `Z:\` as the value.

## For a terminal session

Run the following command to set `BLAB_SHARE_PATH` to `/Volumes/Fas-Phyc-PEB-Lab`

```
$ export BLAB_SHARE_PATH=/Volumes/Fas-Phyc-PEB-Lab
```

## For a single command

To run a python script called `foo.py` that resides in the current directory, temporarily setting the environment variable `BLAB_SHARE_PATH` to `Volumns/Fas-Phyc-PEB-Lab`, run

```
$ BLAB_SHARE_PATH=/Volumes/pn-schmopus python foo.py
```
