Use it for interactive work and scripts that need more than POSIX sh.
Bash
Bash is the GNU Bourne-Again Shell, the default interactive shell on most distributions. It adds arrays, [[ ]] tests, brace expansion, history and better scripting to the POSIX sh language.
1. Shebang is Bash (not sh)?
2. bash -n script.sh — syntax OK?
3. shellcheck script.sh — warnings to fix?
4. bash -x script.sh — where does it go wrong?
5. Check $? after the failing command.
script starts with the Bash shebang → parsed → each line expanded → commands run → exit code returned
For Shell & Bash → Bash, continue with the first unproven Topic check: Record $BASH_VERSION, invocation name, shell flags/options and whether the shell is interactive/login/non-interactive. If that boundary is healthy, advance to the adjacent check: Verify the interpreter actually executing the file and identify Bash-specific constructs before portability assumptions. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
bash --versionPrimary Commands
Configuration and operational commands for this Topic.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
interpreter selection → Bash version + invocation mode → startup/options → parse Bash grammar → expansions/builtins/functions → external commands/processes → status/signals → script/workload outcome
Healthy evidence: the intended Bash interpreter/version executes the code with known options and produces the expected argv/state/result for representative inputs.
Step 2 Commands Verify boundary
bash --version
bash -n script.sh # syntax check
shellcheck script.sh
Step 3 Verification and output interpretation Verify boundary
Existing fast checks for this Topic. - Record $BASH_VERSION, invocation name, shell flags/options and whether the shell is interactive/login/non-interactive.
- Verify the interpreter actually executing the file and identify Bash-specific constructs before portability assumptions.
- Inspect shopt/set options that affect globbing, error handling, pipelines, inheritance and expansion.
- Run representative tests under the target Bash version/mode and verify downstream state rather than syntax alone.
Verification chain. interpreter selection → Bash version + invocation mode → startup/options → parse Bash grammar → expansions/builtins/functions → external commands/processes → status/signals → script/workload outcome
Step 4 Specialized verification Verify boundary
Reproduce under the same Bash binary and mode, then identify command resolution with type/command-style inspection and inspect shell options when semantics matter. Use xtrace only when safe, and remember that it shows expanded commands rather than the exact original source. Check the exit status at the correct layer, especially pipelines and command substitutions, and verify redirections/file descriptors. The closing evidence is the target state or workload result produced by the script, not merely that Bash parsed the file or returned zero.
Step 5 Failure modes and next checks Narrow the fault
Suspicious evidence: code is tested interactively but run non-interactively, invoked by sh, or relies on Bash/version-specific behavior that is absent on the target.
Step 6 Special cases and limits Narrow the fault
Bash errors can originate before an external command runs, while external command failures can be misread as shell defects. A successful pipeline status may represent only the last command unless pipefail changes it. set -e has context-dependent exceptions and is not transactional rollback. Quoting protects against shell interpretation but does not validate the data for the called program. Keep shell parsing, executable resolution, process exit status and the subsystem being modified as separate evidence boundaries.
Step 7 Common mistakes Narrow the fault
- Missing
set -euo pipefailin scripts.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Start scripts with #!/usr/bin/env bash or #!/bin/bash and set -euo pipefail to stop on errors. Quote variables ("$x"). Check scripts with shellcheck.
bash -x script.sh— trace each expanded commandbash -n script.sh— syntax check onlyshellcheck script.sh— common bugs and quoting problemsecho $?— exit code of the last command
ReferenceWhat it is1 section · depth on demand
Core model
Determine whether code is actually executed by Bash rather than /bin/sh or another shell, then pin Bash version and shell options. Separate portable shell syntax from Bash-specific features and validate behavior in the same interactive/non-interactive/login mode as production.
ReferenceImportant terms & boundaries6 sections · depth on demand
What this shows and what it does not
Bash correctness is scoped to the exact Bash version, invocation mode/options and tested inputs; syntax validity does not show portable or production-correct behavior.
In depth
Bash quoting and special parameters
Most Bash surprises come from quoting. The bash(1) manual page defines four quoting mechanisms:
- Backslash quotes the next character.
- Single quotes preserve everything literally. A single quote can't appear inside single quotes, even escaped.
- Double quotes preserve everything except
$, backquote,\and, with history expansion,!. $'...'decodes escapes such as\n,\t,\xHHand\uHHHH.
Special parameters (manual)
| Parameter | Meaning |
|---|---|
$0 | Name of the shell or script |
$1 … $9, ${10} | Positional parameters; braces from 10 upwards |
$# | Number of positional parameters |
$@ / $* | All parameters; "$@" keeps each one as a separate word |
$? | Exit status of the last command |
$$ | PID of the shell (the parent's PID inside a subshell) |
$! | PID of the last background job |
$- | Current shell option flags |
Quoting in practice
| Write | Result |
|---|---|
echo "$file" | Safe with spaces and wildcards in the name |
echo $file | Split into words and glob-expanded: a bug if the name has spaces or * |
printf '%s\n' "$@" | Each argument on its own line, unchanged |
echo 'Cost: $5' | Literal dollar sign |
echo $'line1\nline2' | A real newline |
grep "it's" file | A single quote inside double quotes |
host$ f='Q4 report*.csv'
host$ touch "$f" 'Q4 report final.csv'
host$ ls $f
ls: cannot access 'Q4': No such file or directory
Q4 report*.csv Q4 report final.csv
host$ ls "$f"
'Q4 report*.csv'
host$ set -- "a b" c
host$ for x in "$@"; do echo "[$x]"; done
[a b]
[c]
host$ for x in $*; do echo "[$x]"; done
[a]
[b]
[c]
Reading the example
Unquoted, $f was split at the space into "Q4" and "report*.csv", and the second word was then glob-expanded. That made ls show two unrelated files. Quoting variables unless word splitting is deliberately wanted prevents a whole class of bugs. shellcheck reports missing quotes automatically.
Documented example, not captured output.
How it works at runtime
Bash is part of Shell & Bash → Bash. Bash is the GNU Bourne Again Shell implementation commonly used interactively and for scripts, adding arrays, [[ ]], arithmetic, brace expansion, shell options, programmable completion and other behavior beyond portable POSIX sh.
Topic-specific state model. Bash is the GNU Bourne Again Shell implementation commonly used interactively and for scripts, adding arrays, [[ ]], arithmetic, brace expansion, shell options, programmable completion and other behavior beyond portable POSIX sh.
Technical metadata. Host/distribution/kernel, Bash/shell version and invocation mode, login/interactive state, cwd/mount namespace, uid/gid, locale/IFS, shell options, startup files, variable/environment state, source command/script, quoting/expansion, final argv, fd 0/1/2 and redirections, pipeline stages/PIPESTATUS, path/inode/object metadata, exit status/signal, target read-back, original workload result.
Interpretation rule. - #!/bin/bash or #!/usr/bin/env bash ≠ the script was necessarily invoked through that interpreter when called as sh script or sourced.
- Bash syntax ≠ POSIX sh portability.
- set -e behavior ≠ simple fail-fast semantics in every conditional, pipeline, subshell or command substitution context.
- Bash version ≠ identical feature/default behavior across distributions.
Specialized mechanics
Bash processes input through tokenization, parsing, expansions, redirections and command execution. Parameter, command and arithmetic expansion occur before the external program receives argv, while quoting controls which characters survive expansion and field splitting. Commands can resolve to aliases, functions, builtins, hashed paths or external executables. Pipeline construction, subshells, job control and exit-status rules add another layer. Debugging Bash therefore requires distinguishing the source text from the argv, environment and file descriptors actually delivered to the command.
Quick reference
Bash features beyond POSIX sh:
| Feature | Example |
|---|---|
[[ ]] tests | [[ $f == *.log && -s $f ]] |
| Arrays | hosts=(web01 web02); echo "${hosts[@]}" |
| Associative arrays | declare -A port=([http]=80 [https]=443) |
| Parameter expansion | ${file%.log}, ${var:-default}, ${s//a/b} |
| Process substitution | diff <(ssh a cat /etc/hosts) <(ssh b cat /etc/hosts) |
| Brace expansion | mkdir -p app/{bin,etc,log} |
set -o pipefail | Pipeline fails if any part fails |
bash --version
help set; help declare
Limits and how it fails
Primary failure point. Bash correctness is scoped to the exact Bash version, invocation mode/options and tested inputs; syntax validity does not show portable or production-correct behavior.
ReferenceConfiguration & state2 sections · depth on demand
Configuration, persistence and lifecycle
Distribution/platform context. Shell & Bash owns shared execution model; individual child Topics own expansion, redirection, variables, functions, scripts and status/signal semantics.
Specialized lifecycle
Behavior depends on Bash version, invocation name and whether the shell is login, interactive, non-interactive or POSIX mode. Startup files, BASH_ENV, shell options, shopt settings, locale, PATH, functions and environment inheritance can make interactive success differ from cron/systemd/CI execution. Scripts should declare the intended interpreter, quote expansions deliberately and choose error-handling behavior consciously rather than assuming set -e is a complete safety model. Keep secrets out of tracing and do not depend on aliases or interactive profile state in automation.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Shell & Bash → Bash. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.gnu.org/software/bash/manual/bash.html · confidence 94%Authoritative Linux project/vendor documentation reviewed for bounded reference claims: shell parsing, expansion, execution environment and exit semantics. Documentation-based technical verification only; not lab or production-runtime proof. The schema vendor_doc method is used for authoritative project/vendor documentation; deployment applicability remains separate evidence.
Basis: https://www.gnu.org/software/bash/manual/bash.html · confidence 93%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Bash operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for Bash.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | Bash is the GNU Bourne Again Shell implementation commonly used interactively and for scripts, adding arrays, [[ ]], arithmetic, brace expansion, shell options, programmable completion and other behavior beyond portable POSIX sh. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin host/distribution + shell/version/mode → identify cwd/mount namespace + input/path/stream → preserve quoting/expansion and final argv → map fd/pipeline/process boundaries → inspect object/variable/status/signal state → make one minimal reversible change → read back effective state → repeat original consumer/script/workload test. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | interpreter selection → Bash version + invocation mode → startup/options → parse Bash grammar → expansions/builtins/functions → external commands/processes → status/signals → script/workload outcome | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | Bash correctness is scoped to the exact Bash version, invocation mode/options and tested inputs; syntax validity does not prove portable or production-correct behavior. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux file/text/shell evidence can establish this proof path: interpreter selection → Bash version + invocation mode → startup/options → parse Bash grammar → expansions/builtins/functions → external commands/processes → status/signals → script/workload outcome | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove behavior outside the captured host, shell/session, cwd/namespace, input, process, filesystem, locale, time or workload scope. Bash correctness is scoped to the exact Bash version, invocation mode/options and tested inputs; syntax validity does not prove portable or production-correct behavior. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven boundary: capture the exact shell-delivered argv/streams or resolved object, verify the effective target state, change only the demonstrated cause, then repeat the original consumer/script/workload and adjacent regression checks. | Continue to the next unresolved boundary while preserving the original test condition. |
Bash · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | Bash |
|---|---|
| Topic path | Shell & Bash → Bash |
| Runtime state | Bash is the GNU Bourne Again Shell implementation commonly used interactively and for scripts, adding arrays, [[ ]], arithmetic, brace expansion, shell options, programmable completion and other behavior beyond portable POSIX sh. |
| Fast checks | - Record $BASH_VERSION, invocation name, shell flags/options and whether the shell is interactive/login/non-interactive. - Verify the interpreter actually executing the file and identify Bash-specific constructs before portability assumptions. - Inspect shopt/set options that affect globbing, error handling, pipelines, inheritance and expansion. - Run representative tests under the target Bash version/mode and verify downstream state rather than syntax alone. |
| Verification chain | interpreter selection → Bash version + invocation mode → startup/options → parse Bash grammar → expansions/builtins/functions → external commands/processes → status/signals → script/workload outcome Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary. |
| Failure boundary | Bash correctness is scoped to the exact Bash version, invocation mode/options and tested inputs; syntax validity does not prove portable or production-correct behavior. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |
Bash · specialized operational reference
Topic-specific Linux mechanics, lifecycle, proof path and failure-boundary lookup.
| Operational boundary | Topic-specific reference |
|---|---|
| Execution path | Parse → expand → redirect → resolve → execute → wait |
| Context | Version + login/interactive mode + options + locale |
| Resolution | Alias/function/builtin/hashed/external |
| Proof | Correct exit semantics plus verified target state |