Chapter 2. Introducing the Shell

So, you can run commands at a prompt. But what is that prompt? Where does it come from, how are your commands run, and why does it matter?

That little prompt is produced by a program called a shell. It’s a user interface that sits between you and the Linux operating system. Linux supplies several shells, and the most common (and the standard for this book) is called bash. (See Appendix B for notes about other shells.)

bash and other shells do much more than simply run commands. For example, when a command includes a wildcard (*) to refer to multiple files at once:

$ ls *.py
data.py    main.py    user_interface.py

the wildcard is handled entirely by the shell, not by the program ls. The shell evaluates the expression *.py and invisibly replaces it with a list of matching filenames before ls runs. In other words, ls never sees the wildcard. From the perspective of ls, you typed the following command:

$ ls data.py main.py user_interface.py

The shell also handles the pipes you saw in Chapter 1. It redirects stdin and stdout transparently so the programs involved have no idea they are communicating with each other.

Every time a command runs, some steps are the responsibility of the invoked program, such as ls, and some are the responsibility of the shell. Expert users understand which is which. That’s one reason they can create long, complex commands off the top of their head and run them successfully. They already know what the command will do before they ...

Get Efficient Linux at the Command Line now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.