Use it when a command behaves differently in a script, a cron job or another user's session.
Shell
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.
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".
shell started (login/interactive/non-interactive) → startup files read → command line expanded → program executed
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
Operational reference
Fast context before you go deeper.
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
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 · 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.
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.
echo $0; ps -p $$ -o comm=— shell currently runninggetent passwd $USER | cut -d: -f7— login shelltype <name>— alias, function, builtin or filebash -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_loginand~/.profilethat 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_ENVvariable, 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 starts | Type | Files read |
|---|---|---|
| SSH login, console login | Login, interactive | /etc/profile, ~/.bash_profile (often sources ~/.bashrc) |
| New terminal window in a desktop | Usually interactive, non-login | ~/.bashrc |
ssh host command | Non-interactive (bash may still read ~/.bashrc; see the manual) | Varies |
A script (#!/bin/bash) | Non-interactive | Only $BASH_ENV |
| cron, systemd services | Non-interactive, minimal environment | None of the user's files |
sudo -i / su - | Login shell of the target user | That user's login files |
Telling them apart
| Test | Shows |
|---|---|
shopt -q login_shell && echo login | Whether this is a login shell |
[[ $- == *i* ]] && echo interactive | Whether this is interactive |
echo $0 | -bash (leading dash) for login shells |
Where settings belong
| Setting | File |
|---|---|
| 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 services | The 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.
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.
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
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 Linux Fundamentals → Shell. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.kernel.org/ · confidence 94%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
Shell operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for Shell.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | 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. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin 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 chain | shell implementation + mode → parse/tokenize → expansion/quoting → builtin/function/alias or PATH resolution → process/redirection/pipeline → exit status → target-state verification | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | 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. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated 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 verification | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It 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 check | Continue 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 boundary | Shell |
|---|---|
| Topic path | Linux Fundamentals → Shell |
| Runtime state | 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. |
| 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 chain | shell 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 boundary | 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. 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. |