Introduction to the Shell

The command line is a method of human-computer interaction that offers an alternative to the point and click, graphical user interface (GUI) you are probably most used to. Fundamentally it is analagous to a conversation between human and computer: verbal commands are typed at a keyboard and verbal text output is printed in response. It’s a method that predates even the use of video displays, as early command line interfaces made use of teletypewriters to type input and print output onto rolls of paper.

ASR-33 at CHM.agr

Unix, a hugely popular and influential operating system developed in the 1970s, uses a program called a shell to handle command line interaction, so-called because it acts as a wrapper around the operating system kernel, presenting a user-friendly interface.

A shell program isn’t really that complicated: it reads input, evaluates commands, runs programs and waits for them to complete, and then prints any output to the screen. Its simplicity obeys the original Unix design philosophy which encourages developers to write programs to do one thing and do it well.

On its own, a shell isn’t very useful as there isn’t really much functionality built into it. Basic functions such as copying a file or listing the contents of a directory are actually provided by other programs; the shell just calls them. Again, this is because of the “do one thing and do it well” philosophy.

Typically, when you’re using the command line, there will be a whole suite of pre-installed programs available to run via the shell, and many more can be installed. So, when people talk about “the shell”, they often really mean “the shell and all of the useful little programs that come along with it”.

But, with all of these programs having been written by different people over many years, it’s imperative that there’s a level of consistency in how they interact with the shell and with each other. This consistency is delivered by another key part of the Unix design philosophy: “expect the output of every program to become the input to another, as yet unknown program”. Or alternatively: “write programs to handle text streams, because that is a universal interface”. By designing tools in this way, the shell is able to let users string commands together, sending data straight from one program to another. This is part of what makes the command line such a useful tool: simple parts, closely linked can be built up into more complex and useful functions.

Screenshot of bash shell

The other key strength of the command line is that any command you type can be kept and used again later. Most shell programs keep a history of your recent commands and make it easy to go back and repeat things, and you can also create shell scripts by writing sequences of commands into a text file. These scripts are really useful for automating common tasks and can be used just like any other program. Although graphical user interfaces are by far the most popular means of interacting with a computer these days, you’ll see that the shell isn’t a throwback to a bygone age, but a tool that can greatly increase your productivity (with a bit of practice).

The Unix family of operating systems has diverged and evolved over the years, and many popular operating systems (OSs) such as Linux, OSX and Android can trace their roots back to Unix. Many different shell programs have been written too, but the basic concept remains the same, and most Unix-based OSs come with a shell built in. The default shell for most Linux systems is called bash, and that’s what we’ll be using in this course, but you should be aware that there are many other versions of the shell. Csh, tcsh, ksh and zsh are also popular and are preferred by some users because they offer additional functionality.

Next activity: Module 3 - Navigating Files and Directories.