# Bash Bash (Bourne Again Shell) is a Unix [[Shell]] and command language. Created by [[Brian Fox]] for the GNU Project in 1989, it's the default shell on most Linux distributions and was macOS's default until Catalina (2019). Bash is both an interactive command interpreter and a scripting language. It combines features from the original Bourne shell (sh) with additions from the Korn shell (ksh) and C shell (csh). ## Key Features - **[[POSIX]] compliance**: Compatible with sh scripts - **Command history**: Navigate and search previous commands - **Tab completion**: Auto-complete files, directories, and commands - **Aliases**: Create shortcuts for frequently used commands - **Functions**: Define reusable command sequences - **Arrays**: Both indexed and associative arrays - **Arithmetic**: Built-in integer arithmetic - **Job control**: Manage background and foreground processes ## Basic Syntax ### Variables ```bash name="value" # Assignment (no spaces around =) echo "$name" # Access with $ echo "${name}_suffix" # Braces for clarity ``` ### Conditionals ```bash if [[ $x -gt 5 ]]; then echo "Greater than 5" elif [[ $x -eq 5 ]]; then echo "Equal to 5" else echo "Less than 5" fi ``` ### Loops ```bash for item in "${array[@]}"; do echo "$item" done while [[ condition ]]; do # commands done ``` ### Functions ```bash my_function() { local arg1="$1" echo "Argument: $arg1" return 0 } ``` ## Configuration Files - `~/.bashrc`: Executed for interactive non-login shells - `~/.bash_profile`: Executed for login shells - `~/.bash_aliases`: Common place for alias definitions - `~/.bash_history`: Command history storage ## Useful Built-ins - `cd`: Change directory - `pwd`: Print working directory - `echo`: Print text - `export`: Set environment variables - `source` (or `.`): Execute script in current shell - `alias`: Create command shortcuts - `history`: View command history ## References - https://www.gnu.org/software/bash/ - https://en.wikipedia.org/wiki/Bash_(Unix_shell) ## Related - [[Brian Fox]] - [[Shell]] - [[Zsh (Z Shell)]] - [[Git Bash]] - [[TMux]] - [[jq]] - [[Command Line Interface (CLI)]] - [[Discover Bash aliases and understand why those are great (Article)]] - [[POSIX]]