Przejdลบ do treล›ci

๐Ÿš 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
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     User        โ”‚  ๐Ÿ‘ˆ You are here
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚      SHELL      โ”‚  ๐Ÿ‘ˆ bash, zsh, sh (Interprets commands)
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚     KERNEL      โ”‚  ๐Ÿ‘ˆ Linux/Unix Core (Manages CPU, RAM, Disk)
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚    HARDWARE     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

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

  1. REPL: Read-Eval-Print Loop. The cycle of reading input, executing it, printing output, and waiting for more.
  2. Built-ins: Commands inside the shell itself (e.g., cd, echo, export). They are faster because no new process is createdยน.
  3. 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.