Kahibaro
Discord Login Register

2.1.1 What is a shell?

Understanding the Shell

At the command line in Linux, you are not talking directly to the kernel or the operating system. You are talking to a program whose job is to interpret what you type and make things happen. That program is called a shell.

The Shell’s Role

A shell is:

Conceptually, a shell sits between you and the kernel:

The shell is not the terminal emulator itself (like GNOME Terminal, Konsole, etc.). The terminal displays text and handles keyboard input; the shell runs inside that terminal.

Interactive vs Non‑Interactive Use

Shells can run in two main modes:

Interactive shells

You use these directly:

Typical use:

In an interactive shell, features like command history and tab completion are active (covered in other chapters).

Non‑interactive shells

These do not wait for your input; instead, they run commands from a file or from another program:

  #!/bin/bash
  echo "Hello from a script"

In non‑interactive mode, the shell mostly just executes what is given, without interactive niceties.

Types of Shells

There are multiple shell implementations on Linux. Each is a program with its own features and scripting “dialect”, but all serve the same basic role.

Common shells include:

Shell choice affects:

The detailed comparison of bash, zsh, and fish is covered separately; here it’s enough to know that “the shell” is a type of program, and there are several variants you can choose from.

Login vs Non‑Login Shells

Shells are also distinguished by how they are started:

Login shells

Started when you log into the system:

Login shells typically read system and user startup files (like /etc/profile and ~/.profile or ~/.bash_profile, depending on the shell) to set up your environment.

Non‑login shells

Started inside an existing session, for example:

These usually read different initialization files (like ~/.bashrc for bash) appropriate for interactive use.

Details of shell configuration files are discussed elsewhere, but the key point here is: how your shell starts affects what configuration files it reads and therefore what environment you get.

Built‑ins vs External Commands

When you type a command, the shell may:

  1. Run a built‑in command:
    • Implemented inside the shell program.
    • Does not require starting a new process.
    • Examples (names vary slightly by shell): cd, echo, pwd, export, alias.
  2. Run an external command:
    • A separate executable file in the filesystem.
    • The shell finds it via the $PATH environment variable (details in later chapters).
    • Examples: /bin/ls, /usr/bin/grep, /usr/bin/python.

The shell decides which one to use by:

You can see how a shell resolves a command (for example, in bash or zsh):

Understanding this resolution process is essential when commands don’t behave as expected (e.g. an alias overrides an external command).

The Shell as a Programming Language

Besides running single commands, a shell includes a full (though limited) programming language. This allows:

Example of a simple shell one-liner:

[ -d mydir ] && echo "Directory exists" || echo "Directory missing"

This illustrates that the shell is not just a “command runner”; it has syntax and rules that are interpreted before your commands reach the kernel.

Full shell scripting is handled in a later part of the course; here, the key point is that the shell is also a scripting environment.

The Shell and the Terminal

It’s common to confuse the shell with the terminal:

You can even run a shell inside another shell (for example, starting bash from a zsh session) because from the outer shell’s point of view, the inner shell is just another program.

Why the Shell Matters

For Linux users and administrators, the shell is important because it:

As you progress, you’ll move from simply typing commands into the shell to using it as a powerful, scriptable interface to the entire system.

Views: 79

Comments

Please login to add a comment.

Don't have an account? Register now!