Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

Shell

Direct answer

The shell is the command interpreter: it reads commands, expands variables, globs and substitutions, sets up pipes and redirection, and starts programs. Bash is the common default; sh (dash on Debian) is a smaller POSIX shell.

When to use this

Use it when a command behaves differently in a script, a cron job or another user's session.

First 30 seconds

1. Which shell runs it? Check the shebang and ps -p $$.

2. Works interactively but not in cron? PATH and startup files differ — use full paths.

3. type <cmd> — alias or function hiding the real command?

4. bash -x the script to see expansions.

5. Quote variables: "$var".

Operational verification

shell started (login/interactive/non-interactive) → startup files read → command line expanded → program executed

Evidence · next step

For Linux Fundamentals → Shell, continue with the first unproven Topic check: Identify shell implementation, login/interactive mode and the exact command text/context. If that boundary is healthy, advance to the adjacent check: Resolve aliases/functions/builtins before assuming PATH selected an external executable. 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
Scope / prerequisiteUse it when a command behaves differently in a script, a cron job or another user's session.
What next?3 suggested next steps
Evidence1
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.

5 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 implementation + mode → parse/tokenize → expansion/quoting → builtin/function/alias or PATH resolution → process/redirection/pipeline → exit status → target-state verification

Healthy evidence: shell implementation/mode, parsing path, command type, exit status and resulting target state are all known for the failing invocation.

Step 2 Verification and output interpretation Verify boundary

Existing fast checks for this Topic. - Identify shell implementation, login/interactive mode and the exact command text/context.

  • Resolve aliases/functions/builtins before assuming PATH selected an external executable.
  • Separate expansion, quoting, redirection and pipeline behavior from the invoked program's own behavior.
  • Capture exit status and verify the resulting target state rather than judging only stdout/stderr.

Verification chain. shell implementation + mode → parse/tokenize → expansion/quoting → builtin/function/alias or PATH resolution → process/redirection/pipeline → exit status → target-state verification

Step 3 Commands Verify boundary
echo $SHELL
cat /etc/shells
chsh -s /bin/bash alice
Step 4 Failure modes and next checks Narrow the fault

Suspicious evidence: terminal and shell are conflated, aliases/functions are ignored, interactive success is extrapolated to automation, or output is treated as success without exit/state evidence.

Step 5 Common mistakes Narrow the fault
  • Scripts relying on the interactive shell.
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

Scripts run by sh do not support Bash features ([[ ]], arrays) — use #!/bin/bash. Login, interactive and non-interactive shells read different startup files, so aliases and PATH changes may be missing in scripts and cron.

Key checks
  • echo $0; ps -p $$ -o comm= — shell currently running
  • getent passwd $USER | cut -d: -f7 — login shell
  • type <name> — alias, function, builtin or file
  • bash -x script.sh — trace each command as it runs
ReferenceWhat it is1 section · depth on demand

Core model

Identify the exact shell implementation and invocation mode, then separate parsing/expansion from executable lookup and child-process execution. Determine whether a command is a shell builtin, function, alias or external program, capture environment/redirection/pipeline context, and verify the exit status plus resulting state.

ReferenceImportant terms & boundaries5 sections · depth on demand

What this shows and what it does not

A shell can successfully parse and launch a command while the external operation still fails; conversely, terminal I/O problems can occur before shell semantics are involved.

In depth

The shell: login, interactive and non-interactive shells

A shell reads commands and runs them. Which start-up files it reads depends on how it was started, and that explains many "works in my terminal, fails in cron" problems. The bash(1) manual page defines the rules:

  • A login shell, such as an SSH login or bash -l, reads /etc/profile, then the first of ~/.bash_profile, ~/.bash_login and ~/.profile that exists.
  • An interactive non-login shell, such as a new terminal tab, reads ~/.bashrc.
  • A non-interactive shell, which is what runs scripts, reads none of these. It only reads the file named by the BASH_ENV variable, if that's set.

Many distributions make ~/.bash_profile source ~/.bashrc, so login shells get the same settings.

Which shell type is used where

How it startsTypeFiles read
SSH login, console loginLogin, interactive/etc/profile, ~/.bash_profile (often sources ~/.bashrc)
New terminal window in a desktopUsually interactive, non-login~/.bashrc
ssh host commandNon-interactive (bash may still read ~/.bashrc; see the manual)Varies
A script (#!/bin/bash)Non-interactiveOnly $BASH_ENV
cron, systemd servicesNon-interactive, minimal environmentNone of the user's files
sudo -i / su -Login shell of the target userThat user's login files

Telling them apart

TestShows
shopt -q login_shell && echo loginWhether this is a login shell
[[ $- == *i* ]] && echo interactiveWhether this is interactive
echo $0-bash (leading dash) for login shells

Where settings belong

SettingFile
Environment variables for the whole session (PATH, EDITOR)~/.profile or ~/.bash_profile
Aliases, prompt, shell options, completion~/.bashrc
System-wide for all users/etc/profile.d/*.sh
For servicesThe unit's Environment= or EnvironmentFile=
host$ shopt -q login_shell && echo login || echo non-login; [[ $- == *i* ]] && echo interactive
non-login
interactive
host$ echo 'alias ll="ls -alF"' >> ~/.bashrc
host$ cat ~/.bash_profile
[ -f ~/.bashrc ] && . ~/.bashrc
export PATH="$HOME/.local/bin:$PATH"
host$ env -i HOME=$HOME /bin/bash -c 'type ll; echo "PATH=$PATH"'
/bin/bash: line 1: type: ll: not found
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Reading the last test

With an empty environment, a non-interactive bash, like cron's, has neither the alias nor ~/.local/bin on its PATH. Scripts should therefore set the PATH they need, and use full commands, not aliases.

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 is part of Linux Fundamentals → Shell. Shell is a command-language interpreter and process launcher, not the terminal itself. Shell behavior depends on implementation plus login/interactive/non-interactive mode, parsing, expansions, builtins, environment inheritance and exit-status handling.

Topic-specific state model. Shell is a command-language interpreter and process launcher, not the terminal itself. Shell behavior depends on implementation plus login/interactive/non-interactive mode, parsing, expansions, builtins, environment inheritance and exit-status handling.

Interpretation rule. - Shell ≠ terminal emulator or TTY.

  • Text that looks like a command ≠ one external executable; it may be a builtin, function or alias.
  • Command printed/output produced ≠ exit status is success.
  • Interactive shell behavior ≠ non-interactive script behavior.

Quick reference

The shell interprets commands, expands variables and globs, manages jobs and runs scripts. Common shells: bash (default on most distros), zsh (macOS default, power users), dash (/bin/sh on Debian/Ubuntu — POSIX only, faster for scripts), fish.

echo $SHELL; ps -p $$
cat /etc/shells
chsh -s /bin/zsh
ls -l /bin/sh                 # dash or bash?

Scripts with #!/bin/sh must avoid bash-only syntax ([[ ]], arrays, ${var//x/y}) because they may run under dash. Check portability with shellcheck -s sh.

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. A shell can successfully parse and launch a command while the external operation still fails; conversely, terminal I/O problems can occur before shell semantics are involved.

ReferenceConfiguration & state1 section · depth on demand

Configuration, persistence and lifecycle

Distribution/platform context. Shell owns generic interpreter/session semantics. Bash-specific scripting depth lives in Shell & Bash, while terminal/TTY and executable search have their own Fundamentals Topics.

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

Basis: https://docs.kernel.org/ · 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 shell basicscommand shell linuxshell vs terminal
Embedded reference data

Quick lookup tables

Shell operational reference

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

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateShell is a command-language interpreter and process launcher, not the terminal itself. Shell behavior depends on implementation plus login/interactive/non-interactive mode, parsing, expansions, builtins, environment inheritance and exit-status handling.Establish exactly what this Topic owns before crossing into another subsystem.
Fast verificationPin distribution/release + CPU architecture + running kernel → identify the exact process/session and kernel-versus-user-space boundary → capture shell/TTY mode and effective environment where relevant → resolve the real executable/consumer → correlate requested action with observed runtime state → verify the original workload result before changing persistent configuration.Use the shortest evidence path first; a fast check is a boundary test, not blanket proof.
Verification chainshell implementation + mode → parse/tokenize → expansion/quoting → builtin/function/alias or PATH resolution → process/redirection/pipeline → exit status → target-state verificationTrace requested/configured state through effective state to the observed workload result.
Failure boundaryA shell can successfully parse and launch a command while the external operation still fails; conversely, terminal I/O problems can occur before shell semantics are involved.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated host, process/session and runtime evidence can establish this Linux Fundamentals proof path: shell implementation + mode → parse/tokenize → expansion/quoting → builtin/function/alias or PATH resolution → process/redirection/pipeline → exit status → target-state verificationUse this observation only for the specific claim it actually supports.
Evidence limitIt does not independently prove behavior outside the captured host, kernel, process/session, environment or workload scope. A shell can successfully parse and launch a command while the external operation still fails; conversely, terminal I/O problems can occur before shell semantics are involved.Do not promote a local success signal into end-to-end or adjacent-dependency proof.
Next troubleshooting checkContinue from the first unproven Linux layer: preserve platform identity and the running kernel, inspect the exact process/session and effective configuration/environment, resolve the actual consumer/executable, then verify the original workload before moving into the owning Linux subsystem branch.Continue to the next unresolved boundary while preserving the original test condition.

Shell · operational reference

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

Reference boundaryShell
Topic pathLinux Fundamentals → Shell
Runtime stateShell is a command-language interpreter and process launcher, not the terminal itself. Shell behavior depends on implementation plus login/interactive/non-interactive mode, parsing, expansions, builtins, environment inheritance and exit-status handling.
Fast checks- Identify shell implementation, login/interactive mode and the exact command text/context. - Resolve aliases/functions/builtins before assuming PATH selected an external executable. - Separate expansion, quoting, redirection and pipeline behavior from the invoked program's own behavior. - Capture exit status and verify the resulting target state rather than judging only stdout/stderr.
Verification chainshell implementation + mode → parse/tokenize → expansion/quoting → builtin/function/alias or PATH resolution → process/redirection/pipeline → exit status → target-state verification 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 boundaryA shell can successfully parse and launch a command while the external operation still fails; conversely, terminal I/O problems can occur before shell semantics are involved. 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?