35.7 Common Variables: HOME, USER, SHELL, TERM, EDITOR, LANG

Right, let’s talk about the environment. No, not the one with trees and guilt—I’m talking about your shell’s environment. It’s the collection of key-value pairs that every program you run inherits. Think of it as a cheat sheet you hand to every application so it knows how to behave. Get these wrong, and otherwise sane programs will start doing the weirdest things. Let’s break down the usual suspects. The Absolute Non-Negotiables: HOME, USER, SHELL These are the bedrock. Your HOME directory is your user’s throne room. It’s where your files live, your preferences are stored, and where most programs will start looking for your stuff by default. It’s set automatically at login, and you should never, ever change it manually. Just don’t.

35.6 PATH: How the Shell Finds Executables

Right, let’s talk about the PATH. This is the single most important environment variable you will ever wrestle with, and if you’ve ever typed a command and gotten a furious command not found back, you’ve already met it. Think of your PATH as the shell’s little black book of dive bars and restaurants. When you shout “I want pizza!” (pizza), the shell doesn’t search the entire city. It frantically checks this specific list of directories you’ve given it, in order, to see if pizza is on the menu in any of them. The moment it finds one, it stops looking. This is why you can’t just drop an executable anywhere and expect the shell to find it; you have to tell the shell which dive bars serve your kind of pizza.

35.5 /etc/profile and /etc/profile.d: Login Shell Initialization

Alright, let’s talk about the big guns: /etc/profile and its sidekick directory, /etc/profile.d/. This is where system-wide shell configuration kicks off for login shells. Think of this as the town square announcement that happens every single time you, or any other user, properly log in. Now, why should you care? Because this is where your operating system or your overzealous sysadmin sets the stage. It’s where global PATH variables are set, where environment variables that every application might need (think JAVA_HOME, EDITOR) are defined, and where umask values are enforced. It runs for every user on a login, making it incredibly powerful and, consequently, a fantastic way to break everyone’s system if you edit it carelessly. No pressure.

35.4 /etc/environment: System-Wide Variable Definitions

Right, let’s talk about /etc/environment. This is the system’s blunt instrument for setting environment variables. It’s not a script; it’s a simple, key-value pair file that gets read by every single login process on the box. Think of it as the global, mandatory bulletin board for the entire operating system. If you need a variable—like a critical path or a license server address—to be set for every user, from the grizzled sysadmin to the freshly created www-data user, this is your place.

35.3 env: Viewing and Setting the Environment

Right, let’s talk about your environment. No, not the mess of coffee cups on your desk—the one your shell lives in. This is the collection of key-value pairs, the environment variables, that every process on your system inherits from its parent. They’re the global settings, the secret handshakes, and the configuration flags that make everything from your prompt to your package manager behave. Think of them as the notes you hastily scribble on a post-it and stick to your monitor; every program you start from that shell gets to read that note.

35.2 export: Marking Variables for Child Process Inheritance

Right, let’s talk about export. You’ve probably already set a variable like MY_VAR="some value" and then felt a profound sense of betrayal when you ran a script and it had absolutely no idea that MY_VAR existed. Welcome to the party. This is the entire reason the export command was invented. Think of your shell session as a gated community. When you declare a variable with a simple assignment, it’s a private citizen of that community. It can’t leave, and nothing outside can see it. When you run another script or program (what we call a child process), it’s like spawning a new, separate gated community next door. By default, it doesn’t get a copy of your community’s private citizens.

35.1 Environment Variables: What They Are and How Processes Inherit Them

Right, let’s talk about environment variables. Forget the dry, academic definition for a moment. Think of them as little sticky notes your operating system slaps onto every program you run. When a program (or “process,” if we’re being formal) needs to know something about the world it’s running in—like where to find your documents, what your username is, or which language you prefer—it just checks these sticky notes. It’s a brilliantly simple system for configuration and communication, and it’s one of the first things you need to wrap your head around.

— joke —

...