Getting Started with Bash
Bash · Reference cheat sheet
Getting Started with Bash
Bash · Reference cheat sheet
📋 Overview
Bash (Bourne Again SHell) is a command-line shell and scripting language common on Linux and macOS. You type commands interactively or save them in a script (*.sh) starting with a shebang.
🔧 Core concepts
| Idea | Meaning |
|---|---|
| Shell | Program that reads commands and runs programs |
| Prompt | Where you type ($ often means a normal user) |
| Command | Program name + arguments: ls -la |
| Script | File of commands executed in order |
| Shebang | #!/usr/bin/env bash on line 1 of scripts |
| Exit status | 0 usually means success; non-zero means failure |
On Windows you can use Git Bash, WSL, or another Unix-like environment.
💡 Examples
Who am I / where am I:
whoami
pwd
echo "Hello from Bash"Check Bash version:
bash --version
echo "$BASH_VERSION"Minimal script (hello.sh):
#!/usr/bin/env bash
set -euo pipefail
echo "Hello, World!"chmod +x hello.sh
./hello.shRun a one-liner without a file:
bash -c 'echo hi; pwd'⚠️ Pitfalls
- Spaces matter:
cd My Dirfails; usecd "My Dir". - Your login shell might be zsh on macOS — scripts can still use Bash via shebang.
- Copying Windows paths (
C:\...) into Bash needs/c/...or WSL paths. - Forgetting
chmod +xleads to “Permission denied” on./script.sh.