Bash
GNU Bourne-Again Shell
Most popular shell, standard on Linux systems with rich scripting capabilities
Overview
Bash (GNU Bourne-Again Shell) is the default shell on most Linux distributions and was the default on macOS until Catalina. Created by Brian Fox in 1989 as a free software replacement for the Bourne shell, Bash has become the de facto standard for shell scripting.
Quick Facts
| Full Name | GNU Bourne-Again Shell |
| Category | Posix |
| POSIX Compliant | Yes |
| Config File | .bashrc / .bash_profile |
| Default On | Most Linux distributions, macOS (before Catalina) |
| First Release | 1989 |
Who Should Use Bash?
- System administrators - Automation and server management
- Developers - Build scripts and development workflows
- Linux users - Default interactive shell on most systems
- Script writers - Portable scripts across Unix-like systems
Installation
Bash is pre-installed on most Unix-like systems.
# Check Bash version
bash --version
# Install on macOS (if needed)
brew install bash
# Install on Debian/Ubuntu
sudo apt install bash
# Set as default shell
chsh -s /bin/bashBasic Usage
Basic Bash commands and syntax.
# Variables
NAME="World"
echo "Hello, $NAME!"
# Arrays
fruits=("apple" "banana" "cherry")
echo ${fruits[0]} # apple
# Conditionals
if [ -f "file.txt" ]; then
echo "File exists"
fi
# Loops
for i in {1..5}; do
echo "Number: $i"
doneConfiguration
Bash configuration files and customization.
# ~/.bashrc - Interactive non-login shells
# ~/.bash_profile - Login shells
# Add to ~/.bashrc
export PS1="\u@\h:\w\$ " # Custom prompt
export PATH="$HOME/bin:$PATH"
# Aliases
alias ll='ls -la'
alias gs='git status'
# Reload configuration
source ~/.bashrcKey Features
Command History
Access previous commands with arrow keys and history command
Tab Completion
Auto-complete file names, commands, and arguments
Job Control
Run processes in background with & and manage with fg/bg
Scripting
Full programming language with functions, arrays, and control structures
FAQ
What is the difference between .bashrc and .bash_profile?
.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells. On macOS, .bash_profile is typically used; on Linux, both are common.
Is Bash POSIX compliant?
Bash is mostly POSIX compliant but includes many extensions. Use "bash --posix" or "set -o posix" for strict POSIX mode.
Summary
Key takeaways for Bash:
- Most widely used shell with extensive documentation
- Pre-installed on almost all Linux distributions
- Powerful scripting capabilities with POSIX compatibility
- Large ecosystem of tools and frameworks
Official Documentation
For authoritative information, refer to the official documentation: