Use it when an alias or setting works in some terminals but not others, or a new shell prints errors.
.bashrc
~/.bashrc is read by every interactive non-login Bash (a new terminal window, bash). It holds aliases, functions, prompt and shell options.
1. bash -x -i -c exit 2>&1 | tail — errors while loading?
2. Setting missing in SSH sessions → is ~/.bashrc sourced from ~/.profile?
3. scp/rsync failing → remove output from ~/.bashrc.
4. source ~/.bashrc after edits.
5. Open a new terminal to confirm.
interactive non-login shell starts → reads /etc/bash.bashrc then ~/.bashrc → aliases, functions and options set
For Shell & Bash → .bashrc, continue with the first unproven Topic check: Identify exact Bash invocation mode and the startup-file chain that applies on the target distribution/user. If that boundary is healthy, advance to the adjacent check: Trace variable/function/alias definitions in source order and look for conditionals/early returns. 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
Bash invocation mode → system startup files → ~/.bashrc eligibility/source order → conditionals/definitions → effective shell variables/functions/aliases/options → command behavior
Healthy evidence: a fresh target-mode Bash reads the intended startup chain, produces no unintended automation output and exposes the expected effective aliases/functions/options/environment.
Step 2 Verification and output interpretation Verify boundary
Existing fast checks for this Topic. - Identify exact Bash invocation mode and the startup-file chain that applies on the target distribution/user.
- Trace variable/function/alias definitions in source order and look for conditionals/early returns.
- Test a fresh shell of the same mode instead of relying only on source ~/.bashrc in the current contaminated session.
- Verify the final command resolution/environment and original interactive workflow after changes.
Verification chain. Bash invocation mode → system startup files → ~/.bashrc eligibility/source order → conditionals/definitions → effective shell variables/functions/aliases/options → command behavior
Step 3 Commands Verify boundary
cat ~/.bashrc
source ~/.bashrc
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: the wrong shell mode is tested, definitions are overridden later, unconditional output breaks SCP/automation, or current-shell state hides startup defects.
.bashrc verification requires a fresh matching shell mode and read-back of effective state; file edits or manual sourcing alone do not show future sessions.
Step 5 Common mistakes Narrow the fault
- Putting output-producing commands in .bashrc (breaks scp/sftp).
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.
Login shells (SSH, console) read ~/.profile or ~/.bash_profile instead; most distributions source ~/.bashrc from there. Keep output (echo) out of ~/.bashrc — it breaks scp/rsync. Test changes with source ~/.bashrc.
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
Do not assume every Bash process reads ~/.bashrc. Determine invocation mode, BASH_ENV, system-wide startup files and whether ~/.profile or another login file sources it. Keep interactive conveniences guarded when they would break non-interactive contexts.
ReferenceImportant terms & boundaries5 sections · depth on demand
What this shows and what it does not
.bashrc verification requires a fresh matching shell mode and read-back of effective state; file edits or manual sourcing alone do not show future sessions.
.profile owns common login-session startup; Variables/Aliases/Functions own individual constructs; this Topic owns Bash interactive startup-file behavior.
In depth
~/.bashrc: configuration for interactive shells
~/.bashrc configures every interactive non-login Bash shell. The bash(1) manual page says this file is read by interactive shells that aren't login shells. --norc skips it, and --rcfile names another file. Login shells don't read it by themselves, so ~/.bash_profile normally sources it, so that every interactive shell gets the same settings.
What belongs in .bashrc
| Content | Example |
|---|---|
| Aliases and functions | alias ll='ls -lh', source ~/.bash_functions |
| Prompt | PS1='\u@\h:\w\$ ' |
| History settings | HISTSIZE, HISTCONTROL, shopt -s histappend |
| Shell options | shopt -s checkwinsize globstar |
| Completion | source /usr/share/bash-completion/bash_completion |
What doesn't belong there
| Content | Better place | Why |
|---|---|---|
PATH additions and exported variables | ~/.profile / ~/.bash_profile | Set once per login and inherited |
| Commands that print output | Guarded by an interactive check | Output breaks scp, sftp and rsync |
| Long-running commands | Nowhere | They slow every new shell |
The interactive guard
Many distributions start .bashrc with a check that returns at once for non-interactive shells. Some non-interactive programs, such as ssh host command on many systems, read .bashrc too. Output or prompts in it can break file transfers.
host$ head -5 ~/.bashrc
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
host$ cat >> ~/.bashrc <<'EOF'
alias ll='ls -lh --group-directories-first'
[ -f ~/.bash_functions ] && . ~/.bash_functions
PS1='\[\e[1;32m\]\u@\h\[\e[0m\]:\w\$ '
shopt -s checkwinsize
EOF
host$ bash -n ~/.bashrc && echo syntax-ok
host$ source ~/.bashrc
host$ ssh srv1 true && echo "non-interactive ssh ok"
host$ ls /etc/skel/
Testing safely
bash -n checks the syntax without running anything. Open a second terminal before logging out, in case the new file breaks the shell. New users get their initial .bashrc copied from /etc/skel when their account is created with useradd -m.
Documented example, not captured output.
How it works at runtime
.bashrc is part of Shell & Bash → .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.
Topic-specific state model. .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.
Interpretation rule. - Editing ~/.bashrc ≠ current shell state changes until sourced or a new applicable shell starts.
- .bashrc ≠ guaranteed login-shell startup file unless the login profile sources it.
- Sourcing .bashrc in automation ≠ harmless when it prints output, changes cwd, aliases commands or starts agents.
- Correct file content ≠ effective value if later startup code overrides it.
Quick reference
~/.bashrc runs for interactive non-login shells (new terminal tabs, bash inside a session). Typical content: aliases, functions, prompt, history settings.
# keep non-interactive shells (scp, rsync) silent
case $- in *i*) ;; *) return;; esac
export PS1='\u@\h:\w\$ '
[ -f ~/.bash_aliases ] && . ~/.bash_aliases
Output from .bashrc in non-interactive sessions breaks scp/rsync/sftp — guard it as above. System-wide: /etc/bashrc (RHEL) or /etc/bash.bashrc (Debian).
Limits and how it fails
Primary failure point. .bashrc verification requires a fresh matching shell mode and read-back of effective state; file edits or manual sourcing alone do not show future sessions.
ReferenceConfiguration & state1 section · depth on demand
Configuration, persistence and lifecycle
Distribution/platform context. .profile owns common login-session startup; Variables/Aliases/Functions own individual constructs; this Topic owns Bash interactive startup-file behavior.
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 → .bashrc. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.gnu.org/software/bash/manual/bash.html · 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
.bashrc operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for .bashrc.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | .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. | 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 | Bash invocation mode → system startup files → ~/.bashrc eligibility/source order → conditionals/definitions → effective shell variables/functions/aliases/options → command behavior | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | .bashrc verification requires a fresh matching shell mode and read-back of effective state; file edits or manual sourcing alone do not prove future sessions. | 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: Bash invocation mode → system startup files → ~/.bashrc eligibility/source order → conditionals/definitions → effective shell variables/functions/aliases/options → command behavior | 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. .bashrc verification requires a fresh matching shell mode and read-back of effective state; file edits or manual sourcing alone do not prove future sessions. | 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. |
.bashrc · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | .bashrc |
|---|---|
| Topic path | Shell & Bash → .bashrc |
| Runtime state | .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. |
| Fast checks | - Identify exact Bash invocation mode and the startup-file chain that applies on the target distribution/user. - Trace variable/function/alias definitions in source order and look for conditionals/early returns. - Test a fresh shell of the same mode instead of relying only on source ~/.bashrc in the current contaminated session. - Verify the final command resolution/environment and original interactive workflow after changes. |
| Verification chain | Bash invocation mode → system startup files → ~/.bashrc eligibility/source order → conditionals/definitions → effective shell variables/functions/aliases/options → command behavior 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 | .bashrc verification requires a fresh matching shell mode and read-back of effective state; file edits or manual sourcing alone do not prove future sessions. 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. |