Objective. Students will configure the shell environment by setting and exporting variables, modifying PATH, and customizing .bashrc and .bash_profile to support a reproducible development workspace.
This lesson, its worked examples and its practice questions has not yet been verified by an industry-certified professional or by a certification or approval body. It is a study draft and may contain errors. Do not use it as instructions for work on a job site or on live equipment. Always follow your instructor, your supervising professional, and current official references and regulations.
VoTechWorks program approval and accreditation are still in progress. Credentials are issued only by the certifying bodies named in each program, after their own exams.
When you open a Bash terminal, the shell maintains two overlapping collections of data: shell variables and environment variables. Understanding the difference is essential for configuring a reliable development workspace.
A shell variable exists only inside the current shell process. You create one by assigning a name and value:
```bash
MY_VAR="hello"
```
No other process can see `MY_VAR`. When you launch a script or a child shell, it does not inherit this variable.
An environment variable is a shell variable that has been exported. Exporting marks the variable so that every child process the shell spawns inherits a copy of it:
```bash
export MY_VAR="hello"
```
You can combine assignment and export on one line, which is the most common style.
To inspect environment variables, use `env` or `printenv`. To see all variables — including unexported shell variables and shell functions — use `set`. The difference matters in practice: a variable you forget to export will appear in `set` output but not in `env`, and a script run as a child process will not see it.
`PATH` is one of the most important environment variables. It is a colon-separated list of directories the shell searches, in order, when you type a command name. If a directory is not in `PATH`, you must type the full path to any executable stored there.
Developers commonly create a personal `~/bin` directory to store custom scripts and small tools. To make those files available as commands, `~/bin` must be added to `PATH`:
```bash
export PATH="$HOME/bin:$PATH"
```
Placing `$HOME/bin` at the front gives your personal scripts priority over system-wide commands with the same name. Be intentional about ordering: putting an untrusted directory at the front of `PATH` is a security risk if others can write to it. Keep `~/bin` writable only by you (`chmod 700 ~/bin` or `chmod 755 ~/bin` with appropriate permissions).
Bash reads different files depending on how the shell was started.
Because these two startup paths exist, developers use a common pattern: put all customizations in `.bashrc` and source `.bashrc` from `.bash_profile`:
```bash
[[ -f ~/.bashrc ]] && source ~/.bashrc
```
This ensures your settings load regardless of how the shell starts.
Aliases defined in `.bashrc` are also limited to the current shell; they are not inherited by child processes. That is expected behavior — aliases are a convenience shortcut, not a subprocess tool.
Example alias for a common Git command:
```bash
alias gst="git status"
```
After editing `.bashrc`, apply changes to the running shell with:
```bash
source ~/.bashrc
```
or the equivalent shorthand `. ~/.bashrc`.
A `PROJECT_ROOT` environment variable gives scripts and tools a single, authoritative reference to your project directory. Set and export it in `.bashrc`:
```bash
export PROJECT_ROOT="$HOME/projects"
```
Scripts can then use `$PROJECT_ROOT` instead of hardcoded paths, making the workspace easier to move or reproduce.
A dotfile is any configuration file whose name begins with a dot (`.bashrc`, `.bash_profile`, etc.). Keeping these files under version control and writing a `setup.sh` script to deploy them is a professional practice called dotfile management.
A minimal `setup.sh` might:
1. Copy your customized `.bashrc` to `~/`.
2. Copy your `.bash_profile` to `~/`.
3. Create `~/bin` if it does not exist.
4. Source `.bashrc` to apply changes immediately.
Test the script on a clean-user account to simulate a fresh environment before relying on it.
Answer each question, then check it. Nothing is recorded; this is your own practice.
A free tech program — complimentary, as our commitment to get America working. Help us build VoTechWorks. Tell us what works, what doesn’t, and what you want to learn.