How the Shell Finds Things
Variables, the environment, PATH and permissions: the reasons behind the two most common error messages.
Updated
Variables
- Variables in the Shell (Apprentice): A shell variable is a name the shell keeps a value under, so owl_folder=… stores a long path once and $owl_folder hands it back in any command until you close the window.
- Environment Variables: export and env (Apprentice): Programs you start can't see your shell variables, only environment variables, so export shares a variable with them, env and printenv show what they'll see, and NAME=value in front of a command sets one for that command alone.
- PATH: How a Command Is Found (Apprentice): When you type a command's name, the shell looks for a program file of that name in each folder of PATH, in order, so "command not found" means none of them has it, and adding a folder to PATH lets you run its programs by name from anywhere.
Permissions
- Permissions: Read, Write and Run (Apprentice): Every file says who may read it, change it and run it, for its owner, its group and everyone else; ls -l shows it as letters such as rwxr-xr-x, chmod +x lets a program run, and chmod 644 or 600 sets all nine at once with numbers.
- sudo and Who Owns a File (Journeyman): Every file has an owner and a group, and only root, the computer's administrator account, may change anything; sudo runs one command as root after asking for your password, and chown gives a file a new owner, so both are used rarely and on purpose.
Exercise: The Workshop's Machines
- Exercise: The Workshop's Machines (Apprentice): Get an inventor's machines running with ls -l and chmod, an environment variable and a folder added to PATH, keep the broken one switched off, answer seven questions about permissions, owners and commands, and let a check script tell you what's done.