# Shell A shell is a program that provides a [[Command Line Interface (CLI)]] to interact with an operating system. It interprets user commands and executes them, acting as an intermediary between the user and the operating system kernel. The term "shell" comes from the idea of a protective outer layer around the kernel; the shell wraps the core system, providing a user-friendly way to access its functionality. ## Key Functions - **Command interpretation**: Parses and executes user commands - **Scripting**: Supports writing scripts to automate tasks - **Environment management**: Handles variables, paths, and configuration - **Job control**: Manages background and foreground processes - **I/O redirection**: Pipes and redirects input/output streams - **Globbing**: Expands wildcards and patterns ## Types of Shells ### Unix/Linux Shells - **sh (Bourne Shell)**: The original Unix shell - [[Bash]] **(Bourne Again Shell)**: Most common Linux default - **[[Zsh (Z Shell)]]**: Modern shell with advanced features, macOS default - **fish**: User-friendly with syntax highlighting and autosuggestions - **dash**: Lightweight POSIX-compliant shell - **ksh (Korn Shell)**: Combines features of sh and csh ### Windows Shells - **cmd.exe**: Traditional Windows command prompt - **PowerShell**: Object-oriented shell with .NET integration - [[Git Bash]]: Bash emulation for Windows ## Shell vs Terminal - **Shell**: The program that interprets commands ([[Bash]], zsh, fish) - **Terminal**: The interface that displays the shell (iTerm2, Windows Terminal, Alacritty) Think of it this way: the terminal is the window, the shell is the program running inside it. ## Common Shell Features - **Tab completion**: Auto-complete commands and paths - **History**: Access previous commands with arrow keys - **Aliases**: Create shortcuts for common commands - **Functions**: Define reusable command sequences - **Startup files**: `.bashrc`, `.zshrc` for configuration ## Keyboard Shortcuts (readline / bash / zsh) | Shortcut | Action | |----------|--------| | `Ctrl+W` | Delete word to the left of cursor | | `Alt+D` | Delete word to the right of cursor | | `Ctrl+U` | Delete from cursor to start of line | | `Ctrl+K` | Delete from cursor to end of line | | `Ctrl+A` | Move cursor to start of line | | `Ctrl+E` | Move cursor to end of line | | `Alt+B` | Move cursor back one word | | `Alt+F` | Move cursor forward one word | | `Ctrl+R` | Reverse search through command history | | `Ctrl+L` | Clear terminal screen | | `Ctrl+C` | Cancel current command | | `Ctrl+D` | Send EOF / exit shell | ## References - https://en.wikipedia.org/wiki/Shell_(computing) ## Related - [[Bash]] - [[Zsh (Z Shell)]] - [[Git Bash]] - [[TMux]] - [[Command Line Interface (CLI)]] - [[Terminal User Interface (TUI)]]