Frequently Asked Question

What exactly is a shell?

A shell is a program that reads commands you type, works out what they mean, and runs them. It is called a shell because it wraps around the kernel: you talk to the shell, the shell talks to the kernel via system calls, and the kernel talks to the hardware. There is nothing magical about it, the shell is just an ordinary user-space program, which is why Linux has so many of them and why you can swap one for another at will.

When you press Enter on ls -la, the shell parses the line into words, expands anything that needs expanding (variables, wildcards, command substitutions), searches the directories listed in PATH for a program called ls, forks a new process, execs the binary, waits for it to finish, and then prints the prompt again. That same loop (read, parse, expand, fork, exec, wait) happens for every command. The shell is also a complete programming language, which is why the same syntax you type interactively at the prompt can be saved in a file and executed as a script.

Video

Further reading and video