![[MSRP My Project Plan-7.png|300]]
# Unix
> - [Unix for the Beginning Mage](https://dasher.wustl.edu/chem430/readings/unix-tutorial.pdf) (“certified fun”)
## Unix Structure
## Environment Variables
**Environment variables** tell the operating system where in the file system to look for commands, can change the way programs and commands operate, and can even keep track of where you are in the file system.
- `$HOME` - Prints the path to the current user’s home directory
- `$USER` - Prints the current user’s name
- `$PATH` - Prints the existing executable path directories separatated by commas
- Anytime the user runs a command, the operating system will run through this list searching for the appropriate executable file used by thcommand. The OS starts at the beginning of the list and will use the first suitable executable found.
---
These variables can be referenced in programs (such as [[UNIX Terminals|shell scripts]]) to make it more universal by using values provided by the current computer rather than something static/unchanging.
> [!important] **Viewing Environment Variables**
> The command `env` can be used to list all existing environment variables.
> Alternatively, `echo` can be used to list specific variables (`echo $PATH`).
You can also test is an executable is included within the current path system through the `which` command (Ex: `which [command]`).
If the program has been successfully added to the path then the file being used for that command will be printed, if not, then no output will be given.
---
By default, newly defined environmental variables will only be accessible in the environment they were defined in.
- Ex: Running `EXAMPLES=~/Projects/Example_Data` would only let you use the `$EXAMPLES` variable within the terminal
The `export` command can be used to configure the existing environmental variables and ensure that changes made persist. When appending values to pre-existing variables you can add `:$[variable]` to the end of the definition
- Ex: `export PATH=$HOME/.local/bin:$PATH`
---
## Misc
**Ternary Operators:** You can use `? :` to quickly perform actions based on certain condtions
`condition ? expression_if_true : expression_if_false`