Description #
Sh, also known as the Bourne Shell, is the original Unix shell developed at Bell Labs. It became the foundation for most modern Unix shells and scripting standards. It provides basic control flow, file handling, and system command execution — making it suitable for scripting and interactive shell sessions.
History #
Sh was developed in the mid-1970s by Stephen Bourne as a replacement for the Thompson shell in Version 7 Unix. Its syntax and features influenced nearly all Unix shells that followed, including Bash, Ksh, and Zsh. Though it has mostly been replaced in interactive use, its minimalist design still makes it ideal for scripting in system-level tools and embedded systems.
Key milestones:
- 1979: Introduced with Version 7 Unix
- 1980s–1990s: Standard shell across most Unix distributions
- POSIX standardization based on the Bourne Shell’s design
- Still used in system startup scripts and legacy environments
Hello World Code #
#!/bin/sh
echo "Hello, World!"
How to Run #
On any Unix/Linux/macOS system:
- Save the code in a file named
hello.sh
- Make it executable:
chmod +x hello.sh
- Run it:
./hello.sh
The shebang (#!/bin/sh
) ensures it’s executed using the Bourne shell (or a compatible implementation).
Key Concepts #
- Uses a minimal, clean syntax
- Provides control structures like
if
,while
,for
- Supports simple functions and command substitution
- Portable across Unix systems
- Base for POSIX-compliant shell scripting
- Lacks advanced features found in Bash/Zsh (e.g., arrays, arithmetic expansion)
- Often symlinked to Bash in POSIX mode
- Preferred for compatibility in system-level scripts
- Ubiquitous on embedded devices and minimal Unix systems
- Predecessor to Bash and other modern shells
Try It Online #
Fun Facts #
- Stephen Bourne’s original shell source code included ASCII art of his face
- The
.sh
extension for shell scripts is derived from the Bourne Shell - POSIX shell scripting is modeled after
sh
, making it the most portable option - Many system init scripts are still written in pure
sh
- Despite its age, it’s still installed on virtually every Unix-based system