CHAPTER 10 · 6 lessons · 78 exercises
The shell environment
What happens to what you type before it ever reaches the command.
Up to now you have thought that what you type goes to the command as it is. It does not, in fact.
Between you and Linux there is an interpreter called the shell, and it rewrites your letters the moment you press ⏎. Spreading *.txt into a list of file names, putting the real place in for $HOME — that is the shell's work, not the command's.
- environment variables —
echo $HOMEexportenv PATH— the very mechanism by which a command is found- quoting and escaping — the difference between
'and"and\ - the order of expansion — when
*?~$widen out - aliases and history —
aliashistory .profile— the settings read every time you start
This is the chapter with the most "ah, I see" in it. Why typing ls runs ls (PATH), why a space in a file name breaks things (expansion) and why you choose between the quotes (whether $ widens out or not) all join up and come into view.
Once you have this, the way you read an error message changes too, because you can tell apart "the command is at fault" from "the shell handed it something else".
Lessons in this chapter
Variables and PATH
- 52Containers for values (variables)Make the shell remember things. Passing them to a child needs
export.Go to the exercises - 53How a command gets found (`PATH`)Why typing
lsrunsls. Building a toolbox of your own.Go to the exercises
Quoting and expansion
- 54Guarding with quotes (`'`, `"` and `\`)Let the shell rewrite it, or hand it over as it is. Handling names with spaces in them.Go to the exercises
- 55The order things expand in (`~`, `$`, `*`)What the shell does, and in what order, between the return key and the command running.Go to the exercises
Make it a tool of your own
- 56Aliases and historyGive a long command a short name, and call back the moves you typed.Go to the exercises
- 57Writing it down in `.profile`Write your own settings in the file that is read every time you open a terminal.Go to the exercises