What is sh

Last updated: April 1, 2026

Quick Answer: Sh (shell) is a command-line interpreter that processes user commands and executes programs in Unix and Unix-like operating systems, serving as the text-based interface to the system.

Key Facts

Understanding the Shell

Sh, commonly known as the shell or Bourne shell, is a command-line interpreter and programming language interface for Unix and Unix-like operating systems. It serves as the text-based interface between users and the operating system, allowing users to interact with computers through typed commands rather than graphical menus. The shell reads user input, interprets commands, locates and executes programs, manages input and output, and handles the overall flow of system operations. As a foundational component of Unix systems, the shell has been instrumental in shaping how computer users and administrators interact with systems since its development in the 1970s.

History and Development

The original shell, known as the Bourne shell or "sh," was developed by Stephen Bourne at Bell Labs in 1977 as part of Version 7 Unix. It became the standard shell for early Unix systems and established many conventions still used today. The Bourne shell provided the first practical implementation of shell scripting, allowing users to write programs composed of shell commands saved in text files for automated execution. Since its creation, numerous shells have been developed, each building upon or extending the concepts established by the original shell. The shell's influence extends beyond Unix to modern operating systems like Linux and macOS, where shell interpreters remain essential tools for system administration and advanced computing tasks.

Shell Functions and Capabilities

The shell performs several critical functions in computer systems:

Modern Shell Variants

While the original sh (Bourne shell) established the foundation, modern Unix systems use improved variants. Bash (Bourne Again Shell), developed by Brian Fox and maintained by Chet Ramsey, became the most widely used shell, extending the Bourne shell with additional features and improved usability. Bash is the default shell on most Linux distributions and macOS systems. Other popular shells include Zsh (Z shell), which offers enhanced interactive features and customization options; Ksh (Korn shell), which combines features from both Bourne and C shells; and Fish (Friendly Interactive Shell), which prioritizes user-friendliness for interactive use. Despite these variants, all modern shells maintain compatibility with or derive from the original shell's command structure and scripting capabilities.

Shell Scripting

Shell scripting is a powerful capability that allows users to create automated programs using shell commands. A shell script is simply a text file containing a sequence of shell commands that the shell executes sequentially. Shell scripts are commonly used for system administration tasks, backup operations, log file processing, and routine maintenance. Scripts can include variables, control structures (if statements, loops), and functions, making them a complete programming language suitable for many computing tasks. The simplicity and power of shell scripting have contributed to the shell's continued importance in modern computing environments, even as graphical interfaces have become prevalent.

Environmental Variables and Configuration

The shell manages environment variables—named settings that store information about the system configuration, user preferences, and program settings. Common environment variables include PATH (which specifies where the shell searches for executable programs), HOME (the user's home directory), and USER (the current username). Users can customize their shell experience by modifying configuration files such as .bashrc or .zshrc, which contain settings and commands executed when the shell starts. This customization capability allows each user to tailor their shell environment to their preferences and workflow requirements.

Related Questions

What is the difference between sh and bash?

Bash (Bourne Again Shell) is an extended version of sh that includes additional features like command history, programmable completion, and improved scripting capabilities. While sh is more minimal and portable, bash is more feature-rich and user-friendly, becoming the default shell on most Linux systems.

How do you write a shell script?

Shell scripts are text files containing shell commands, starting with a shebang line (#!/bin/sh or #!/bin/bash) indicating the shell to use. Write commands sequentially in the file, make it executable with chmod +x, and run it. Scripts can include variables, loops, and conditionals for complex automation.

What are environment variables in the shell?

Environment variables are named settings storing system configuration and user preferences that programs can access. Common examples include PATH (program search locations), HOME (user directory), and USER (username). Users can view variables with 'env' or 'echo $VARIABLE' and set them in shell configuration files.

Sources

  1. Wikipedia - Unix Shell CC-BY-SA-4.0
  2. Wikipedia - Bourne Shell CC-BY-SA-4.0