Copyright (c) 2026 MindMesh Academy. All rights reserved. This content is proprietary and may not be reproduced or distributed without permission.

2.4.1. The Shell Environment: Variables, Paths, and Configs

💡 First Principle: Environment variables are key-value pairs that programs inherit from their parent process. When you run a script, it inherits a copy of your shell's environment. Changes to variables inside the script don't affect the parent shell — unless you source the script instead of executing it.

Important Environment Variables:
VariablePurposeExample Value
PATHDirectories searched for commands (colon-separated)/usr/local/bin:/usr/bin:/bin
HOMECurrent user's home directory/home/alice
USERCurrent usernamealice
SHELLPath to current shell binary/bin/bash
PS1Primary prompt string[\u@\h \W]\$
DISPLAYX11 display server (for GUI apps via SSH):0 or localhost:10.0
env                           # Print all environment variables
printenv PATH                 # Print a specific variable
export MY_VAR="hello"         # Set and export to child processes
unset MY_VAR                  # Remove a variable
echo $PATH                    # Print PATH value
PATH="$PATH:/opt/myapp/bin"   # Append to PATH (current session only)
Shell Configuration Files — Load Order:
Login shell:           /etc/profile → FIRST found of ~/.bash_profile, ~/.bash_login, ~/.profile
Interactive non-login: /etc/bash.bashrc → ~/.bashrc
Non-interactive:       $BASH_ENV (rarely set)
source ~/.bashrc              # Reload without opening new shell
. ~/.bashrc                   # Equivalent (dot is alias for source)
Path Types:
# Absolute — always starts from /
cd /etc/nginx
cat /home/alice/notes.txt
~                             # Expands to $HOME (/home/alice)

# Relative — from current directory
cd ..                         # Go up one level
cd -                          # Return to previous directory
./script.sh                   # Run script in current directory
ls ../../etc                  # Up two levels, into etc
Aliases:
alias ll='ls -la'             # Create alias (current session)
alias grep='grep --color=auto'
unalias ll                    # Remove alias
alias                         # List all aliases

To make aliases persistent, add them to ~/.bashrc.

⚠️ Exam Trap: Variables set without export are local to the current shell — child processes (scripts, subshells) do not inherit them. export VAR=value makes the variable available to all child processes. This is why a variable you set in your shell may not be visible to a script you run.

Reflection Question: A cron job runs a script that needs to find binaries in /opt/myapp/bin, but it fails with "command not found" even though those commands work fine when you run the script manually. What environment variable is most likely the cause, and how do you fix it?

Alvin Varughese
Written byAlvin Varughese
Founder18 professional certifications
|\r\n| `DISPLAY` | X11 display server (for GUI apps via SSH) | `:0` or `localhost:10.0` |\r\n\r\n```bash\r\nenv # Print all environment variables\r\nprintenv PATH # Print a specific variable\r\nexport MY_VAR=\"hello\" # Set and export to child processes\r\nunset MY_VAR # Remove a variable\r\necho $PATH # Print PATH value\r\nPATH=\"$PATH:/opt/myapp/bin\" # Append to PATH (current session only)\r\n```\r\n\r\n**Shell Configuration Files — Load Order:**\r\n\r\n```\r\nLogin shell: /etc/profile → FIRST found of ~/.bash_profile, ~/.bash_login, ~/.profile\r\nInteractive non-login: /etc/bash.bashrc → ~/.bashrc\r\nNon-interactive: $BASH_ENV (rarely set)\r\n```\r\n\r\n```bash\r\nsource ~/.bashrc # Reload without opening new shell\r\n. ~/.bashrc # Equivalent (dot is alias for source)\r\n```\r\n\r\n**Path Types:**\r\n\r\n```bash\r\n# Absolute — always starts from /\r\ncd /etc/nginx\r\ncat /home/alice/notes.txt\r\n~ # Expands to $HOME (/home/alice)\r\n\r\n# Relative — from current directory\r\ncd .. # Go up one level\r\ncd - # Return to previous directory\r\n./script.sh # Run script in current directory\r\nls ../../etc # Up two levels, into etc\r\n```\r\n\r\n**Aliases:**\r\n\r\n```bash\r\nalias ll='ls -la' # Create alias (current session)\r\nalias grep='grep --color=auto'\r\nunalias ll # Remove alias\r\nalias # List all aliases\r\n```\r\n\r\nTo make aliases persistent, add them to `~/.bashrc`.\r\n\r\n⚠️ **Exam Trap:** Variables set without `export` are local to the current shell — child processes (scripts, subshells) do not inherit them. `export VAR=value` makes the variable available to all child processes. This is why a variable you set in your shell may not be visible to a script you run.\r\n\r\n**Reflection Question:** A cron job runs a script that needs to find binaries in `/opt/myapp/bin`, but it fails with \"command not found\" even though those commands work fine when you run the script manually. What environment variable is most likely the cause, and how do you fix it?\r\n\r\n---\r\n","rawTocMarkdown":"* **Phase 1: First Principles of Linux Systems**\r\n * 1.1. The Linux Philosophy and System Architecture\r\n * 1.2. How Linux Boots: From Power-On to Shell\r\n * 1.3. The Filesystem Hierarchy and Linux Abstractions\r\n * 1.4. Reflection Checkpoint\r\n* **Phase 2: System Management (23%)**\r\n * 2.1. Linux Foundations: Architectures, Distributions, and Licensing\r\n * 2.1.1. Server Architectures and Distribution Families\r\n * 2.1.2. Software Licensing and the Open Source Ecosystem\r\n * 2.1.3. Kernel Modules and Hardware Device Management\r\n * 2.2. Storage and Device Management\r\n * 2.2.1. Partitions, Filesystems, and Disk Layout\r\n * 2.2.2. Logical Volume Manager (LVM)\r\n * 2.2.3. RAID, Mounted Storage, and Network Filesystems\r\n * 2.3. Network Configuration and Tools\r\n * 2.3.1. Network Interface Configuration (NetworkManager and Netplan)\r\n * 2.3.2. Network Diagnostics and Common Tools\r\n * 2.4. Shell Operations and the Command Line\r\n * 2.4.1. The Shell Environment: Variables, Paths, and Configs\r\n * 2.4.2. I/O Redirection, Pipelines, and Essential Utilities\r\n * 2.5. Backup, Restore, and Data Operations\r\n * 2.5.1. Archiving and Compression\r\n * 2.5.2. Disk Duplication and Remote Sync\r\n * 2.6. Virtualization on Linux\r\n * 2.6.1. Hypervisors and Virtual Machine Concepts\r\n * 2.6.2. VM Operations, Networking, and Management Tools\r\n * 2.7. Reflection Checkpoint\r\n* **Phase 3: Services and User Management (20%)**\r\n * 3.1. File and Directory Management\r\n * 3.1.1. File Operations and Navigation\r\n * 3.1.2. Links, Device Files, and Special File Types\r\n * 3.2. Local Account Management\r\n * 3.2.1. Users, Groups, and Account Lifecycle\r\n * 3.2.2. Account Files, UID/GID Ranges, and Profile Templates\r\n * 3.3. Process and Job Management\r\n * 3.3.1. Process Monitoring and States\r\n * 3.3.2. Job Control, Signals, and Scheduling\r\n * 3.4. Software and Package Management\r\n * 3.4.1. Package Managers and Repository Management\r\n * 3.4.2. Service Configurations and Common Daemons\r\n * 3.5. systemd: Service and System Management\r\n * 3.5.1. systemd Units: Services, Timers, Mounts, and Targets\r\n * 3.5.2. Managing Unit States and System Configuration\r\n * 3.6. Container Management\r\n * 3.6.1. Container Runtimes and Image Operations\r\n * 3.6.2. Container Operations, Volumes, and Networking\r\n * 3.7. Reflection Checkpoint\r\n* **Phase 4: Security (18%)**\r\n * 4.1. Authorization, Authentication, and Access Control\r\n * 4.1.1. Privilege Escalation: sudo, su, and Polkit\r\n * 4.1.2. File Permissions, ACLs, and File Attributes\r\n * 4.1.3. SELinux: Mandatory Access Control\r\n * 4.2. Firewalls and Network Security\r\n * 4.2.1. firewalld: Zones, Rules, and NAT\r\n * 4.2.2. nftables, iptables, and IP Forwarding\r\n * 4.2.3. Authentication Services: PAM, SSSD, LDAP, and Kerberos\r\n * 4.3. OS Hardening and Account Security\r\n * 4.3.1. System Hardening Techniques\r\n * 4.3.2. Account Hardening and Password Policies\r\n * 4.4. Cryptography and Data Protection\r\n * 4.4.1. Encryption at Rest: LUKS2 and GPG\r\n * 4.4.2. Encryption in Transit: TLS, WireGuard, and Certificates\r\n * 4.5. Compliance, Auditing, and Vulnerability Management\r\n * 4.5.1. Vulnerability Scanning and File Integrity\r\n * 4.5.2. Audit Logging, OpenSCAP, and Secure Destruction\r\n * 4.6. Reflection Checkpoint\r\n* **Phase 5: Automation, Orchestration, and Scripting (17%)**\r\n * 5.1. Shell Scripting\r\n * 5.1.1. Script Structure, Variables, and Control Flow\r\n * 5.1.2. Input Handling, Error Handling, and Debugging\r\n * 5.1.3. Regular Expressions and Text Processing in Scripts\r\n * 5.2. Infrastructure as Code (IaC)\r\n * 5.2.1. Ansible: Inventory, Playbooks, and Modules\r\n * 5.2.2. Git Version Control and Puppet Overview\r\n * 5.3. Orchestration Concepts and Cloud Integration\r\n * 5.3.1. Kubernetes Concepts and Docker Compose\r\n * 5.3.2. Cloud Platforms and Hybrid Infrastructure\r\n * 5.4. Version Control and Collaboration Workflows\r\n * 5.4.1. Branching Strategies and Merge Conflicts\r\n * 5.4.2. SSH Keys, Signing, and Repository Management\r\n * 5.5. Monitoring and Observability at Scale\r\n * 5.5.1. System Performance Monitoring\r\n * 5.5.2. Observability Stacks and Alerting\r\n * 5.6. Reflection Checkpoint\r\n* **Phase 6: Troubleshooting (22%)**\r\n * 6.1. System and Process Troubleshooting\r\n * 6.1.1. Boot and Kernel Troubleshooting\r\n * 6.1.2. Process, Memory, and Performance Troubleshooting\r\n * 6.2. Storage Troubleshooting\r\n * 6.2.1. Filesystem and Disk Diagnostics\r\n * 6.2.2. Mount, LVM, and RAID Troubleshooting\r\n * 6.3. Network Troubleshooting\r\n * 6.3.1. Network Diagnostic Methodology\r\n * 6.3.2. SSL/TLS, Service, and Firewall Troubleshooting\r\n * 6.4. Application and Service Troubleshooting\r\n * 6.4.1. Service Diagnostics and Dependency Chains\r\n * 6.4.2. Backup Verification and Disaster Recovery\r\n * 6.5. Reflection Checkpoint\r\n* **Phase 7: Exam Readiness**\r\n * 7.1. Exam Strategy and Time Management\r\n * 7.2. Quick Reference\r\n* **Phase 8: Glossary**\r\n\r\n---","examId":"comptia-linux-plus","contentLastUpdated":"2026-07-18"};