What is a shell?
Video 100 of 140 in Virtualization Foundations, in the unit “The shell and the filesystem tree”. 3:13, with English and Hindi audio.
On a Linux server, much of the work happens in a black window with a blinking cursor and no mouse. The program that listens in that window is the shell. If you will run virtual machines, you will type commands into a shell almost every day, so it helps to know what it does with each line. This article explains what a shell is, how a command is built, and what happens between pressing Enter and seeing the output.
What you will learn
- The shell is the program that reads what you type, runs it, and prints the result.
- A command is a program name, followed by arguments and options.
- Pressing Enter sends the line to the shell, which splits it into words and finds the program.
- Some commands, such as cd, are built into the shell itself.
- A typo is the most common mistake, and the shell reports it without breaking anything else.
A black window with no mouse
Picture a night call from a warehouse. Harbor Point Logistics, a fictional logistics firm used for training examples, runs its stock system on a Linux server. An engineer logs in and sees only a black window. There is no mouse to click and no icon to double-click. Everything happens through text.
The program that listens in that window is the shell. Its whole job is to read what you type, understand it, and run it. On Ubuntu and most Linux systems, the usual shell is called bash. On Windows, the equivalent is PowerShell, or the older cmd.exe. The idea is the same.
The parts of one command
Every command has parts. The word at the front is the command, which is the program to run. The words after it are arguments, the things the program should act on, such as a folder name.
- Command: the program to run, such as ls, which lists files.
- Argument: the thing to act on, such as a folder name.
- Option: a switch that changes how the command works. It usually starts with a dash and one letter.
What the shell does between Enter and the output
The shell waits until you press Enter. Then it breaks your line into words. It looks up the program named by the word at the front, and starts it. The program does its work and prints its output into the same window. When it is done, the prompt comes back, ready for another command.
echo one two threetype cdNote: A typo is the most common mistake. The shell replies that it cannot find the command, and nothing else breaks.
Try it yourself
You need a terminal on a Linux machine, such as an Ubuntu server you can log in to. Run three short commands and read what the shell says back.
Print some words. The echo command prints the words that follow it, so the shell shows them back to you.
echo one two threeWhat you should see: The window shows one two three.
Ask the shell what a name is. For cd, the answer shows that it is built into the shell itself.
type cdWhat you should see: The shell replies: cd is a shell builtin.
Make a typo on purpose, to see how the shell reports a command it cannot find.
lss /etcWhat you should see: The shell says it cannot find that command. Your session carries on, ready for the next line.
Terms
- Shell
- The program that reads your commands, runs them, and prints the results.
- Command
- The word at the front of a line, which names the program to run.
- Argument
- A word after the command that names the thing the program should act on, such as a folder.
- Option
- A switch, usually a dash and one letter, that changes how a command works.
Check yourself
What is the difference between an argument and an option?
An argument is the thing the command acts on, such as a folder name. An option is a switch, usually a dash and one letter, that changes how the command works.
What does the shell do after you press Enter?
It splits the line into words, finds the program named by the first word, runs it, and prints the output before the prompt comes back.
Why does a typo produce a message and no damage?
The shell looks for a program with the name you typed. If none exists, it reports that it cannot find the command, and it runs nothing else.
Previous: Checking firmware settings from Linux. Next: Getting help on the command line.