A curated collection of best learning resources on IT topics

All topics -> Languages -> Shell

Shells are command interpreters adopted by Unix-like operating systems. The shell is the program that runs in your terminal when you log in. It allows you to execute other programs, handles I/O redirection, performs various expansions, and so on. Shell commands can be run interactively in the terminal or they can be put in a file and run as a script. Although the shell is a programming language with constructs like if and while, its primary goal is to run, control, and glue together other programs.

The term shell and the idea of a program running other programs was introduced by Louis Pouzin for the Multics operating system in 1964. In 1971, Ken Thompson implemented the first Unix shell known as the Thompson shell (sh) that came with the very first version of Unix. In 1979, it was replaced by the Bourne shell (sh). Another influential shell was the C shell (csh) that found its way into the BSD version of Unix in the late 1970s. Different incompatible shells started to arise, so POSIX defined features that should be common to all Unix shells. A subset of the Korn shell (ksh) was used as a basis for the standard. Bash (bash) is a shell for the GNU Project. It's a default interactive shell on most Linux distributions. Some Linux distributions use Dash (dash) as a scripting shell. While bash extends POSIX, dash tries to be as minimal as possible to conform to the standard. The Z shell (zsh) is another popular shell, which is default on macOS since Catalina.

bash is the most popular shell for scripting because it's so widely available. But since bash is not guaranteed to be present on any Unix-like system, it's a common practice to write scripts using only features defined by POSIX. Which interactive shell to use is more of a matter of personal taste. Both bash and zsh are popular. You may also like fish. New Oil Shell aims to turn a shell into a solid programming language.

Shell scripting has many quirks and legacy features. It's more and more common to see shell scripting being replaced with languages like Python. Nevertheless, shell scripts are not going to go anywhere. They work well for invoking other commands and can be executed almost anywhere.

Links: Unix shell (Wikipedia), Comparison of command shells (Wikipedia), List of Unix commands (Wikipedia), The Origin of the Shell, POSIX Shell & Utilities, ShellCheck, explainshell.com.

Related topics: Unix, Linux.

Here's 7 amazing resources to learn Shell:

  1. Bash Reference Manual (www.gnu.org)
    free • resource • 2023

    The Bash official manual is a great resource that is worth reading from cover-to-cover. It has an advantage of being always at hand with man bash.

  2. GNU Coreutils Manual (www.gnu.org)
    free • resource • 2023

    GNU Coreutils is an implementation of Unix utilities for GNU/Linux distributions. The manual is a nicely structured and detailed description of all the available shell commands. If you want to enlarge your shell vocabulary, this is a perfect resource.

  3. Greg's Wiki (mywiki.wooledge.org)
    free • resource • 2023

    This is an indispensable resource for anyone doing shell programming. BashFAQ tells how to do certain things in Bash, and BashPitfalls tells what to avoid. BashSheet condenses all of the Bash syntax and features on a small page. BashGuide is the best introduction to Bash with lots of examples and practical advice. Although the wiki is devoted to Bash, there is the Bashism page that summarizes Bash-specific features.

  4. POSIX Shell & Utilities (pubs.opengroup.org)
    free • resource • 2018

    This is a POSIX volume that defines the Shell Command Language and utilities that should be present on a Unix system. You won't learn the shell by reading the standard, but the language definition is quite short and readable to be worth checking out. It's the ultimate source of truth on what a POSIX shell is and is not.

  5. The Art of Command Line (github.com)
    free • resource • by Joshua Levy • 2023

    This repo lists shell features and CLI tools that you need to know to master the command line from basics like job and file management to advanced tips and obscure commands.

  6. The Architecture of Open Source Applications: The Bourne-Again Shell (aosabook.org)
    free • article • by Chet Ramey • 2011

    This is a chapter of the AOSA book in which Chet Ramey, the Bash maintainer, explains how Bash works. He gives an overview of the Bash architecture and presents key challenges in the implementation of a real shell.

  7. Build Your Own Shell (github.com)
    free • course • by Julian Squires • 2019

    There are many tutorials on how to build your own toy shell. This one goes further and shows how to implement a real-world, feature-rich shell in multiple stages.