Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

Bash

Direct answer

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.

When to use this

Use it for interactive work and scripts that need more than POSIX sh.

First 30 seconds

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.

Operational verification

script starts with the Bash shebang → parsed → each line expanded → commands run → exit code returned

Evidence · next step

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
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux · Linux · distribution/version specific
Key commandbash --version
Scope / prerequisiteUse it for interactive work and scripts that need more than POSIX sh.
Reference · 1
What next?3 suggested next steps
Catalog command links1
Evidence1
On this pageJump to a specific section
Linux command reference

Primary Commands

Configuration and operational commands for this Topic.

Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

7 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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 pipefail in scripts.
Evidence references

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.

observation · 1
Key points

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.

Key checks
  • bash -x script.sh — trace each expanded command
  • bash -n script.sh — syntax check only
  • shellcheck script.sh — common bugs and quoting problems
  • echo $? — 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, \xHH and \uHHHH.

Special parameters (manual)

ParameterMeaning
$0Name 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

WriteResult
echo "$file"Safe with spaces and wildcards in the name
echo $fileSplit 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" fileA 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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:

FeatureExample
[[ ]] tests[[ $f == *.log && -s $f ]]
Arrayshosts=(web01 web02); echo "${hosts[@]}"
Associative arraysdeclare -A port=([http]=80 [https]=443)
Parameter expansion${file%.log}, ${var:-default}, ${s//a/b}
Process substitutiondiff <(ssh a cat /etc/hosts) <(ssh b cat /etc/hosts)
Brace expansionmkdir -p app/{bin,etc,log}
set -o pipefailPipeline fails if any part fails
bash --version
help set; help declare
Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

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%
2026-09-13 · vendor docGNU Bash 5.3/current

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%
Technical changelog & impact

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.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

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.

Aliases that resolve here
bash linuxgnu bashbash versionbash shell
Embedded reference data

Quick lookup tables

Bash operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for Bash.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateBash 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 verificationPin 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 chaininterpreter selection → Bash version + invocation mode → startup/options → parse Bash grammar → expansions/builtins/functions → external commands/processes → status/signals → script/workload outcomeTrace requested/configured state through effective state to the observed workload result.
Failure boundaryBash 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 evidenceCorrelated 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 outcomeUse this observation only for the specific claim it actually supports.
Evidence limitIt 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 checkContinue 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 boundaryBash
Topic pathShell & Bash → Bash
Runtime stateBash 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 chaininterpreter 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 boundaryBash 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 ruleProve 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 boundaryTopic-specific reference
Execution pathParse → expand → redirect → resolve → execute → wait
ContextVersion + login/interactive mode + options + locale
ResolutionAlias/function/builtin/hashed/external
ProofCorrect exit semantics plus verified target state
Confirmation

Confirm action

Continue?