Skip to main content

Menu

LEVEL 0
0/5 XP
HomeAboutTopicsPricingMy VaultStats

Categories

πŸ€– Artificial Intelligence
☁️ Cloud and Infrastructure
πŸ’Ύ Data and Databases
πŸ’Ό Professional Skills
🎯 Programming and Development
πŸ”’ Security and Networking
πŸ“š Specialized Topics
HomeAboutTopicsPricingMy VaultStats
LEVEL 0
0/5 XP
GitHub
Β© 2026 CheatGridβ„’. All rights reserved.
Privacy PolicyTerms of UseAboutContact

Environment Variables and Shell Configuration Files Cheat Sheet

Environment Variables and Shell Configuration Files Cheat Sheet

Back to Operating Systems and CLI
Updated 2026-05-20
Next Topic: File Permissions Cheat Sheet

Environment variables and shell configuration files form the backbone of how Unix/Linux shells initialize and share state across processes. Every shell session β€” whether opened by logging in, launching a terminal, running a cron job, or spawning a subshell β€” loads a specific subset of configuration files determined by its type, and understanding that type-to-file mapping is the single most important mental model for diagnosing "why doesn't my variable work here?" problems. The distinction between a shell variable (local to the current shell) and an environment variable (inherited by child processes) is equally foundational: export is the bridge between the two. Mastering PATH management, the source built-in, and tools like direnv transforms scattered, session-losing configuration into reproducible, project-aware environments.

What This Cheat Sheet Covers

This topic spans 17 focused tables and 129 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.

Table 1: Shell Session TypesTable 2: Bash Configuration Files and Load OrderTable 3: Zsh Configuration Files and Load OrderTable 4: System-Wide Configuration FilesTable 5: Environment Variable CommandsTable 6: env Command Advanced UsageTable 7: PATH Variable ManagementTable 8: Parameter Expansion and Variable ManipulationTable 9: declare Command Variable AttributesTable 10: Common Predefined Environment VariablesTable 11: XDG Base Directory VariablesTable 12: direnv β€” Project-Level Environment ManagementTable 13: .env File FormatTable 14: Dotfiles Management StrategiesTable 15: mise β€” Polyglot Tool and Environment ManagerTable 16: Shell Environment Debugging TechniquesTable 17: Security Best Practices for Environment Variables

Table 1: Shell Session Types

Every shell falls into one of four quadrants formed by two independent axes: login vs. non-login, and interactive vs. non-interactive. Which configuration files get sourced depends entirely on these two attributes, not on which shell you use.

TypeExampleDescription
Interactive login shell
ssh user@host
bash --login
Reads /etc/profile then the first of ~/.bash_profile, ~/.bash_login, or ~/.profile it finds; this is where session-wide env vars should be set.
Interactive non-login shell
Opening a new terminal tab
Reads only ~/.bashrc (bash) or ~/.zshrc (zsh); the most common day-to-day shell.

More in Operating Systems and CLI

  • Disk and Storage Management in Linux Cheat Sheet
  • File Permissions Cheat Sheet
  • AWS CLI Cheat Sheet
  • GCP CLI Cheat Sheet
  • macOS Usage Cheat Sheet
  • Windows 11 Troubleshooting Cheat Sheet
View all 31 topics in Operating Systems and CLI