Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

Shell & Bash

Direct answer

Shell & Bash covers how commands are parsed, expanded, redirected, piped and run in interactive sessions and scripts, plus the environment and startup files that shape them.

When to use this

Use it as the entry point for command-line and scripting problems.

First 30 seconds

1. Which shell and environment runs it (interactive, cron, systemd)?

2. shellcheck the script.

3. bash -x to see expansions.

4. Check exit codes and PIPESTATUS.

5. Re-run in the target environment.

Operational verification

command line → expansions → redirections and pipes → program runs → exit status

Evidence · next step

For Shell & Bash, continue with the first unproven Topic check: Identify shell implementation/version and whether the session is login, interactive, non-interactive, subshell or script. If that boundary is healthy, advance to the adjacent check: Inspect effective shell options, variables/environment, functions/aliases and startup files from the same execution context. 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
Scope / prerequisiteUse it as the entry point for command-line and scripting problems.
What next?3 suggested next steps
Child topics (this level)16
Evidence2
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

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

6 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

shell invocation/mode → startup files/options → parse syntax → expansion/quote removal → redirection/pipeline/process creation → builtin/function/external command → exit status/signal → target state + workload result

Healthy evidence: effective shell mode/options/startup state are known, expansions produce expected argv/streams, failures propagate as intended and the original command/script behavior is correct.

Step 2 Operational verification Verify boundary

Bash/shell pipelines, environment, scripting and safe operational automation.

Fast verification

  • Quote variable expansions and treat whitespace/globbing as data hazards.

- Check exit codes explicitly; use set -euo pipefail only when its failure semantics are understood.

- Make destructive operations idempotent or guarded, and log the command/context needed to reproduce failures.

Step 3 Verification and output interpretation Verify boundary

Verification path. Reproduce with the same shell binary and mode, then inspect expansion and command resolution before changing data. Use tracing carefully to observe commands after expansion without exposing secrets. Validate exit status at the correct pipeline stage, check file descriptors/redirections, and test representative input including whitespace, glob characters and empty values. For text tools, record locale and regex dialect. Verify the external effect of the script, not merely that parsing completed.

Existing fast checks for this Topic. - Identify shell implementation/version and whether the session is login, interactive, non-interactive, subshell or script.

  • Inspect effective shell options, variables/environment, functions/aliases and startup files from the same execution context.
  • Trace parsing, expansion, quoting, redirection and pipeline boundaries to the exact argv/environment/stdin/stdout/stderr delivered to the target command.
  • Verify exit/status/signal behavior and then repeat the original workload or script acceptance test.

Verification chain. shell invocation/mode → startup files/options → parse syntax → expansion/quote removal → redirection/pipeline/process creation → builtin/function/external command → exit status/signal → target state + workload result

Step 4 Commands Verify boundary
echo $SHELL
bash --version
type ll
set -x  # trace a script
Step 5 Failure modes and next checks Narrow the fault

Suspicious evidence: interactive-only state, unquoted expansion, silent pipeline failure or startup-file differences make the same-looking command behave differently.

It does not show behavior outside the captured host, shell/session, cwd/namespace, input, process, filesystem, locale, time or workload scope. Shell verification ends only when the intended command receives the intended argv/environment/streams and the resulting target state/workload matches expectations; parser or final-command success alone is insufficient.

Next check: Continue from the first step that has not been verified: 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.

Step 6 Common mistakes Narrow the fault
  • Writing bash-specific syntax in #!/bin/sh scripts.
  • Unquoted variables.
Evidence references

Evidence · 2 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 · 1command output · 1
Drill down

Subtopics

Go one level deeper into this subject.

Subtopic 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.

Subtopic Shell Expansion

Shell Expansion is the transformation phase that turns parsed shell words into final arguments and redirection targets through parameter, command, arithmetic, tilde, brace, pathname and word-splitting behavior.

Subtopic Globbing

Globbing is shell pathname expansion that maps wildcard patterns such as *, ?, bracket expressions and Bash glob options to filesystem pathnames before the target command starts.

Subtopic Pipes

Pipes connect one process' stdout to another process' stdin, creating concurrent producer/consumer stages whose buffering, lifecycle and individual exit statuses must be evaluated separately.

Subtopic Redirection

Redirection changes the file-descriptor destinations or sources of a command before execution, enabling files, here-documents, here-strings and descriptor duplication without changing the command's own syntax.

Subtopic stdin / stdout / stderr

stdin, stdout and stderr are conventional file descriptors 0, 1 and 2 inherited by Linux processes; they define data/control/error streams independently of whether a terminal, pipe, file or socket backs each descriptor.

Subtopic Command Substitution

Command Substitution executes a nested command and substitutes its stdout into the surrounding shell word, removing trailing newlines and then subjecting the result to quoting-dependent argument formation.

Subtopic Variables

Bash Variables are shell-name/value bindings distinct from exported environment variables; scope, attributes, arrays, positional parameters and expansion rules determine what child processes and functions actually observe.

Subtopic Aliases

Bash Aliases perform interactive lexical command-name substitution during shell parsing and are primarily a convenience layer, not a reliable scripting or security mechanism.

Subtopic Functions

Bash Functions are named shell command groups executed in the current shell context by default, with positional parameters and access to shell variables, options, traps and descriptors.

Subtopic Bash History

Bash History records selected interactive command lines for recall, but history files, in-memory session state, timestamps and filtering rules make it an incomplete and mutable operational record.

Subtopic .bashrc

.bashrc is a conventional per-user Bash startup file primarily read by interactive non-login Bash shells, often sourced indirectly by login profiles; distribution skeletons can add conditional behavior.

Subtopic .profile

.profile is a conventional per-user login-session initialization file used by Bourne-compatible shells when their shell-specific login file does not supersede it; desktop/session managers may also source it differently.

Subtopic Shell Scripts

Shell Scripts package shell syntax into repeatable executable or sourced files; interpreter selection, permissions, working directory, environment, strictness options and caller context determine their real behavior.

Subtopic Exit Codes

Exit Codes are small integer process/shell statuses used to signal success or categories of failure to a parent shell; Bash also synthesizes statuses for builtins, pipelines, command-not-found and signal termination.

Subtopic Signals

Shell Signals covers how Bash and child processes receive asynchronous POSIX signals, how interactive job control maps terminal actions to process groups, and how traps/termination statuses affect shell-script cleanup.

Key points

Quote variables, check exit codes, and use set -euo pipefail in scripts. Interactive shells, login shells, cron and systemd all have different environments — test scripts the way they will run.

Key checks
  • bash -x script.sh — trace each expanded command
  • shellcheck script.sh — common mistakes
  • type <cmd> — alias, function, builtin or file
  • echo $? — exit code
ReferenceWhat it is3 sections · depth on demand

Operational scope

Bash/shell pipelines, environment, scripting and safe operational automation.

What it is

Bash/shell pipelines, environment, scripting and safe operational automation.

Core model

Reason in shell evaluation order. Source text is parsed into shell syntax; expansions and quote removal create arguments/redirection targets; builtins/functions or external executables run in shell/process contexts; pipelines and asynchronous work create multiple statuses/processes. Verify both shell state and the target program/workload.

ReferenceWhy it matters2 sections · depth on demand

When to use it

Use Shell & Automation when the problem concerns Linux runtime, services, networking, identity, packages, storage or shell automation.

Why it matters operationally

The useful outcome is not simply knowing a definition; it is being able to decide whether Shell & Automation is healthy, misconfigured, missing, or only a symptom of a failure somewhere else.

ReferenceHow it works1 section · depth on demand

How it works

Bash/shell pipelines, environment, scripting and safe operational automation.

ReferenceImportant terms & boundaries4 sections · depth on demand

What this shows and what it does not

Shell verification ends only when the intended command receives the intended argv/environment/streams and the resulting target state/workload matches expectations; parser or final-command success alone is insufficient.

In depth

Interactive and non-interactive Bash, login and non-login

The same bash binary behaves differently depending on how it's started. Two properties matter: whether the shell is interactive, and whether it's a login shell. The bash(1) manual page describes which files each kind reads:

  • Login shells read /etc/profile, then the first readable file of ~/.bash_profile, ~/.bash_login and ~/.profile. They read ~/.bash_logout on exit.
  • Interactive non-login shells read ~/.bashrc.
  • Non-interactive shells read only the file named in BASH_ENV, if any.
  • Bash started as sh reads /etc/profile and ~/.profile as a login shell, and the file in ENV when interactive. It then runs in POSIX mode.

Which kind of shell you get

How the shell startsInteractiveLogin
SSH login, console loginYesYes
su - user, sudo -iYesYes
A new terminal tab in a desktopYesUsually no
bash typed in a shellYesNo
ssh host 'command'NoNo (but Bash may read ~/.bashrc for SSH; distribution-dependent)
A script (#!/bin/bash), cron, systemdNoNo

Checking

TestCommand
Interactive?[[ $- == *i* ]]
Login shell?shopt -q login_shell
Shell nesting levelecho $SHLVL
host$ echo $- ; shopt login_shell
himBHs
login_shell     on
host$ bash -c 'echo $-; shopt login_shell'
hBc
login_shell     off
host$ bash -lc 'shopt -q login_shell && echo login'
login
host$ echo $SHLVL
1
host$ type -a ll cd ls

Why it matters

A variable or alias defined in ~/.bashrc isn't available to cron jobs, systemd units or most scripts, because those shells are non-interactive. Scripts should set everything they need themselves, instead of relying on the user's interactive configuration.

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

Shell & Bash is part of Shell & Bash. Shell & Bash is the command-execution model for Linux interactive and scripted sessions: parsing, expansion, redirection, pipelines, variables/functions, startup files, exit status and signal behavior before commands reach the kernel or external programs.

Runtime state ownership and mechanics. Shell behavior is a parsing and process-construction pipeline: lexical parsing, quoting, expansions, redirections, pipeline setup, command resolution, fork/exec or builtin execution, wait/status collection and signal/job-control handling. Text-processing tools operate on byte or character streams with locale-dependent behavior, and regular expressions differ by tool and mode. A visible command line can therefore differ materially from the argv, file descriptors and environment presented to the executed program.

Topic-specific state model. Shell & Bash is the command-execution model for Linux interactive and scripted sessions: parsing, expansion, redirection, pipelines, variables/functions, startup files, exit status and signal behavior before commands reach the kernel or external programs.

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. - Shell syntax accepted ≠ the intended argv/redirection was produced after expansion.

  • A command shown in history ≠ exact runtime inputs, environment or expansion results are recoverable.
  • Exit status 0 from the last pipeline stage ≠ every command in the pipeline succeeded.
  • Interactive shell behavior ≠ non-interactive script behavior; startup files, aliases, job control and options can differ.

Limits and how it fails

Primary failure point. Shell verification ends only when the intended command receives the intended argv/environment/streams and the resulting target state/workload matches expectations; parser or final-command success alone is insufficient.

Model. A command shown in history is not necessarily what the program received after expansion. Pipeline exit status can represent only one command unless shell options change that behavior. Quoting errors, locale differences and glob expansion can look like tool defects. Builtins and external commands can share names. Successful script exit does not show every intended side effect occurred unless the script checks them. Keep shell semantics separate from the subsystem operated on by the command.

ReferenceConfiguration & state1 section · depth on demand

Configuration, persistence and lifecycle

Configuration intent and lifecycle. Separate shell startup configuration from script code and from the external tools a script invokes. Login versus interactive startup files, set options, aliases/functions, locale, PATH and environment inheritance all affect behavior. Scripts should make interpreter, error handling, quoting and input assumptions explicit. Prefer portable constructs only when portability is a requirement; otherwise record the required shell/tool version. Do not assume an interactive alias, function or profile exists in cron, systemd or automation contexts.

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. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://www.gnu.org/software/bash/manual/bash.html · confidence 94%
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
linux bashshell & automationlinux shell & automationshell bash linuxbash shell referenceShell & Automation troubleshootinglinux shell
Embedded reference data

Quick lookup tables

Shell & Bash operational reference

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

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateShell & Bash is the command-execution model for Linux interactive and scripted sessions: parsing, expansion, redirection, pipelines, variables/functions, startup files, exit status and signal behavior before commands reach the kernel or external programs.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 chainshell invocation/mode → startup files/options → parse syntax → expansion/quote removal → redirection/pipeline/process creation → builtin/function/external command → exit status/signal → target state + workload resultTrace requested/configured state through effective state to the observed workload result.
Failure boundaryShell verification ends only when the intended command receives the intended argv/environment/streams and the resulting target state/workload matches expectations; parser or final-command success alone is insufficient.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: shell invocation/mode → startup files/options → parse syntax → expansion/quote removal → redirection/pipeline/process creation → builtin/function/external command → exit status/signal → target state + workload resultUse 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. Shell verification ends only when the intended command receives the intended argv/environment/streams and the resulting target state/workload matches expectations; parser or final-command success alone is insufficient.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.

Shell & Bash · operational reference

Compact Linux state, persistence, verification and boundary reference for fast lookup.

Reference boundaryShell & Bash
Topic pathShell & Bash
Runtime stateShell & Bash is the command-execution model for Linux interactive and scripted sessions: parsing, expansion, redirection, pipelines, variables/functions, startup files, exit status and signal behavior before commands reach the kernel or external programs.
Fast checks- Identify shell implementation/version and whether the session is login, interactive, non-interactive, subshell or script. - Inspect effective shell options, variables/environment, functions/aliases and startup files from the same execution context. - Trace parsing, expansion, quoting, redirection and pipeline boundaries to the exact argv/environment/stdin/stdout/stderr delivered to the target command. - Verify exit/status/signal behavior and then repeat the original workload or script acceptance test.
Verification chainshell invocation/mode → startup files/options → parse syntax → expansion/quote removal → redirection/pipeline/process creation → builtin/function/external command → exit status/signal → target state + workload result Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary.
Failure boundaryShell verification ends only when the intended command receives the intended argv/environment/streams and the resulting target state/workload matches expectations; parser or final-command success alone is insufficient. 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.
Confirmation

Confirm action

Continue?