DEV Community

Cover image for Unlocking the Command Line: Episode 2 - The Shell and the shell prompt
Emmanuel John Ayarma
Emmanuel John Ayarma

Posted on

Unlocking the Command Line: Episode 2 - The Shell and the shell prompt

In the previous episode, we explored the enduring significance of the Command Line Interface (CLI) and its indispensability for developers, system administrators, and power users. Despite the rise of Graphical User Interfaces (GUIs), the CLI has persisted due to its efficiency, flexibility, and scripting capabilities. In this episode, we will focus on the evolution of the shell and the components of a shell prompt.

The CLI's roots can be traced back to the Multics project, which introduced the concept of a command-line interpreter in the 1960s. It was during this time that the term "shell" was coined by French computer scientist Louis Pouzin.
The Unix operating system, emerging in the early 1970s, brought a powerful command-line environment. The V6 shell, developed by Ken Thompson in 1971, played a pivotal role and heavily influenced subsequent shells.
The Bourne shell, introduced in 1977, replaced the V6 shell and served as an interactive command interpreter and scripting language, featuring structured programming capabilities. It paved the way for shells like KornShell (ksh), Almquist shell (ash), and the popular Bourne-again shell (Bash).

The Z Shell (Zsh), created in 1990, combined features from ksh and tcsh, offering advanced functionalities such as programmable command-line completion, extended file globbing, improved variable/array handling, and customizable prompts.
As Unix gained popularity, different shells were developed to enhance the user experience. The C Shell (csh), created by Bill Joy, introduced features like command-line editing and history. Stephen Bourne developed the Bourne Shell (sh) around the same time.

In the 1980s, the GNU Project aimed to create a free and open-source Unix-like operating system. As part of this project, Brian Fox developed Bash, incorporating features from both the C Shell and the Bourne Shell. Bash's extensive capabilities have made it one of the most popular shells.
The Linux Kernel, developed by Linus Torvalds in 1991, combined with the GNU project's utilities to form the Linux operating system. Typically, the combination of GNU tools, the Linux kernel, and additional software is commonly referred to as a Linux distribution or distro in short. Bash remains the default shell for Unix-like systems, while Zsh is the default on macOS. On Windows, the command prompt (cmd.exe) and PowerShell serve as terminal applications.

Throughout this series, we will primarily focus on Bash due to its ubiquity. Windows users can follow along using Cygwin, an open-source package that provides a Unix-like CLI. Most commands are similar across zsh, bash, and Cygwin, ensuring compatibility.
Bash offers advanced features such as command history, inline editing, scripting capabilities, aliases, and variables. Its extensive feature list includes conditional statements, functions, and more.

Scripting enables us to store pre-defined commands in a file, allowing us to execute them later using the bash shell. It incorporates programming elements that facilitate the automation of sequences, enabling us to accomplish tasks efficiently and swiftly.

Aliases serve as convenient nicknames for commands. They allow us to create shorter versions of lengthy commands, making it easier and quicker to execute them.

Variables are used to store information for both the bash shell and the user. They not only serve as containers for data but can also modify the behavior of commands. By utilizing variables, we can customize and adjust the way commands operate to suit our specific needs.

To open the terminal, Linux or macOS users can simply search for and run the Terminal application. Windows users can open Cygwin after downloading and installing it.
The terminal emulator program mimics the practical terminal discussed in the previous episode as illustrated in the cover image above. When a terminal application is launched, the shell prompt becomes a vital part of the interface. It not only indicates that commands can be executed but also provides valuable information to the user. The prompt's structure may vary between distributions but typically includes

  1. the username
  2. system name or hostname and
  3. current directory (another name for folder).

A terminal window on a linux system

A prompt typically concludes with one of the following characters: $, %, #, :, >, or -.

In Unix and its derivatives, it is common for the prompt to end with $ or % when the user is a regular user, while it ends with # if the user is a superuser (referred to as "root" in Unix terminology).

For example:

Enter fullscreen mode Exit fullscreen mode

The prompt above includes the user's name, system name, and the current directory. In this case, the user's name is yarmycode, the system name is johns-computer and the current directory is ~. The ~ symbol denotes the user's home directory, typically located under /home and named after the user account. We can also tell that yarmycode is a normal user by the $ symbol.

Let's begin by learning our first command, which is used to display our location in the file system (current directory). To print the current working directory, which is usually the user directory when you first open the terminal, type pwd and press the Enter or Return key on your keyboard.

Like so:

yarmycode@johns-computer:~$ pwd
Enter fullscreen mode Exit fullscreen mode


Enter fullscreen mode Exit fullscreen mode

pwd is an abbreviation for print working directory and does exactly what it says.

Now let's print the content of our directory using the ls command. ls is used to list files. In this case ls will list the files in our home directory. Directories are seen as a special type file in Unix-based systems.

yarmycode@johns-computer:~$ ls
Enter fullscreen mode Exit fullscreen mode


Desktop  Documents  Downloads  Music  Pictures
Enter fullscreen mode Exit fullscreen mode

Don't bother about the output of the commands for now. Your output may be different from mine.

We will explore directories in more depth in future episodes, so stay tuned. In the next episode, we will continue to delve into the capabilities and practical applications of the Command Line Interface (CLI). Happy navigating!

Top comments (0)