Q. What methods are there for keeping track of, preserving, and jumping between spawned instances? Is this even possible or do they die on `exit` .
## Questions, research
1. If you create a variable manually I guess it won’t make it to any config file. How would you create a persistent var that is added to the `.bashrc` and thus which would be initialised on every session? Is this where the path comes in?
1. What methods are there for keeping track of, preserving, and jumping between spawned instances? Is this even possible or do they die on `exit` ?
## What is the shell environment and what are environment variables?
- Every time that you interact with the shell you do so within an **environment**. This is the context within which you are working and it determines your access to resources and the behaviour that is permitted.
- Every time a [shell session](https://www.notion.so/Shell-sessions-e6dd743dec1d4fe3b1ee672c8f9731f6) spawns, a process takes place to gather and compile information that should be available to the shell process and its child processes. It obtains the data for these settings from a variety of different files and settings on the system.
As the above shows, a key can have multiple related values. Each one is demarcated with a `:` . If the value is longer than a single word, quotation marks are used.
Variables can be created via config files that run on the initialisation of the session or manually created via the command line in the current session
## What are shell variables useful for?
Some deployment mechanisms rely on environmental variables to configure authentication information. This is useful because it does not require keeping these in files that may be seen by outside parties.
More generally they are used for when you will need to read or alter the environment of your system.
## Viewing shell and environmental variables
To view the settings of your current environment you can execute the `env` command which returns a list of the key-value pairs introduced above. Here are some of the more intelligible variables that are returned when I run this command:
Note that `env` and `printenv` do not show all the shell variables, only a selection. To view all the shell variables along with the environmental variables use `set` .
## Creating, exporting and deleting variable shell and environment variables
You can also add variables to config files that run on login such as your user `.bashrc` / `.zshrc` . This is obviously best for when you want the variables to persist and be accessible within every [shell session](https://www.notion.so/Shell-sessions-e6dd743dec1d4fe3b1ee672c8f9731f6).
## Important environmental and shell variables
### `PATH`
A list of directories that the system will check when looking for commands. When a user types in a command, the system will check directories in this order for the executable.
For example, if you wish to use `npm` commands globally (in any directory) you will need to have the requisite Node executable in your path, which you can see above.
TODO: Add more info about the path when I have it.
### `SHELL`
This describes the shell that will be interpreting any commands you type in. In most cases, this will be bash by default, but other values can be set if you prefer other options.