๐ What is a Shell?
The shell is the primary interface between a user and the operating system kernel. It is a command-line interpreter that reads your commands, translates them into system calls, and executes programs.
๐ก Simple Analogy: If the Kernel is the engine of a car, the Shell is the steering wheel and pedals.
๐บ๏ธ The Layers
1 2 3 4 5 6 7 8 9 | |
When you type ls -la, the shell doesn't know how to list files. It finds the /bin/ls program and asks the Kernel to run it.
๐ Two Modes of Operation
| Mode | Description | Example |
|---|---|---|
| Interactive | You type commands, shell responds. | Your terminal prompt. |
| Non-Interactive | Shell reads commands from a file (script). | CI/CD pipelines, cron jobs. |
๐ง Key Concepts
- REPL: Read-Eval-Print Loop. The cycle of reading input, executing it, printing output, and waiting for more.
- Built-ins: Commands inside the shell itself (e.g.,
cd,echo,export). They are faster because no new process is createdยน. - External Commands: Programs on disk (e.g.,
grep,curl,git). The shell forks a new process to run them.
ยน Footnote: Creating a new process (fork() + exec()) has a small performance cost. In tight loops, using built-ins is significantly faster.