Chapter 6: The Shell Overview Before graphical user interfaces came into vogue, the only way to interact with an operating system was via the command line shell (often known simply as the shell). The shell allows users to type in commands for the operating system and the operating system to display the output that results from the execution of these commands. Despite the rise of GUIs like GNOME and KDE and predictions of the complete demise of the command line shell, the shell has held steady as the user interface of choice for a large number of users - sometimes as a last resort when the GUI fails, but often simply because it is a very flexible and powerful tool. In fact, the shell has evolved into a tool that allows users to do pretty much all that can be done using the operating system - far beyond what a GUI would permit. In this chapter, we’ll be discussing the following: The concepts of a command line shell and its background Shell commands, shortcut keys, and aliases The command line syntax Managing multiple tasks at the same time Using the shell as a scripting language The Shell as a Command Line Interface An operating system such as the Linux kernel consists of code written mostly in the low-level programming language C. The kernel is loaded into memory at the time the machine boots up, and sits there awaiting instructions. There are a number of ways for us to pass instructions to the kernel. One of the most important is to write programs that interact with it - once a program is written, you may compile and execute it to accomplish the task. Since programs written to interact with the kernel often have several tasks in common, there is usually a library of these common tasks, which is a collection of C subroutines (or functions as some might call them) organized into a library. This is simply known as the C library or the libc. While programs that use the C library are powerful and flexible, it is often cumbersome, if not downright impractical, to write a program, compile it, and run it every time we need to do something as simple as copying a file. This is where the shell comes in. The shell is a declarative and parameterized mechanism for executing common tasks. What this means is that the shell allows us to execute programs that are generic enough to take parameters. For example, by using the file copy program cp, supplying a source file and a destination file as parameters (also known as arguments), it is possible to copy a file from one location to another in the file system. The power of the shell comes from the wide gamut of programs that can be executed from it. These programs are what are commonly known as UNIX commands. As some readers might have guessed by now, the shell itself is another program. 161

Hint: This post is supported by Gama besplatan domen provider