Inspect and modify environment variables to troubleshoot session state issues that produce inconsistent tool behavior. Validate PATH, set and verify a project variable, persist it for new shells, then remove it cleanly.
A user reports “command not found” behavior and inconsistent application paths between sessions. Your job is to inspect the current environment, validate PATH, set a project directory variable for a deployment workflow, persist it, then remove it safely.
Environment variables influence process behavior, command lookup, and tool defaults. The operational workflow is to validate current state, apply a minimal change, verify it immediately, then persist it only when required.
PROJECT_DIR.~/.bashrc.export marks a shell variable for inheritance
by processes launched from the session.
~/.bashrc define per-user
session defaults for interactive shells.
unset removes a variable from the current
session, helping you confirm whether values come from
startup files or runtime changes.
echo $PATH
PATH controls where the shell searches for executables. If a user reports missing commands or inconsistent tool versions, verify PATH early and confirm expected directories are present and ordered correctly.
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
printenv
# OR
env
printenv and env provide a snapshot
of session state. This is how you confirm what values are
actually inherited by processes launched from the shell.
SHELL=/bin/bash
USER=lab
LOGNAME=lab
HOME=/home/lab
PWD=/home/lab
HOSTNAME=env-lab
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
LANG=en_US.UTF-8
...
export PROJECT_DIR=/srv/app
export sets the variable in the current shell
and ensures child processes inherit it. Use this when a
program, script, or tool needs a consistent session-level
value.
echo $PROJECT_DIR
Verify immediately after setting the value. This confirms the shell holds the expected path and reduces time spent debugging typos later.
/srv/app
echo 'export PROJECT_DIR=/srv/app' >> ~/.bashrc
Appending to ~/.bashrc ensures the variable is
set each time an interactive shell starts. Persist only when
the user needs the value across sessions.
unset PROJECT_DIR
unset removes the variable from the current
shell session. This helps you test behavior without the
value and confirm whether startup files reintroduce it on
new shells.
If core paths like /usr/bin or /bin
are missing, the shell may fail to find standard tools. Look
for overrides in ~/.bashrc, ~/.profile,
or system-wide shell configuration.
The variable was set for the current shell only. Persist it in the correct startup file and start a new interactive shell to confirm it is applied.
Re-appending the same line creates multiple definitions that are harder to audit. Keep one export line per variable and remove duplicates during cleanup.
Unsetting only affects the current session. If behavior is coming from a startup file or a system service environment, correct the source and validate in a fresh shell or process.
Remove the persistent export if it was only needed for testing, then confirm the variable is not present in a new shell.
grep -n 'PROJECT_DIR' ~/.bashrc
# Remove the line(s) manually if present, then:
unset PROJECT_DIR
echo $PROJECT_DIR is empty in the current shell,
and new shells do not reintroduce the variable unless you
intentionally persist it.
echo $PATH
: Prints the PATH value used for command lookup.
printenv
: Prints environment variables for the current session.
env
: Displays the current environment.
export <name>=<value>
: Sets a variable in the current shell and exports it to
child processes.
echo $<name>
: Prints the current value of an environment variable.
echo 'export <name>=<value>' >> ~/.bashrc
: Persists a variable for new interactive shells.
>>
: Appends to the file without overwriting existing
content.
unset <name>
: Removes a variable from the current shell session.
grep -n <pattern> <file>
: Searches a file for matching lines and shows line numbers.
-n
: Prints line numbers for matches.