Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

.bashrc

Direct answer

~/.bashrc is read by every interactive non-login Bash (a new terminal window, bash). It holds aliases, functions, prompt and shell options.

When to use this

Use it when an alias or setting works in some terminals but not others, or a new shell prints errors.

First 30 seconds

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.

Operational verification

interactive non-login shell starts → reads /etc/bash.bashrc then ~/.bashrc → aliases, functions and options set

Evidence · next step

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
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 an alias or setting works in some terminals but not others, or a new shell prints errors.
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

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

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.

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

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

ContentExample
Aliases and functionsalias ll='ls -lh', source ~/.bash_functions
PromptPS1='\u@\h:\w\$ '
History settingsHISTSIZE, HISTCONTROL, shopt -s histappend
Shell optionsshopt -s checkwinsize globstar
Completionsource /usr/share/bash-completion/bash_completion

What doesn't belong there

ContentBetter placeWhy
PATH additions and exported variables~/.profile / ~/.bash_profileSet once per login and inherited
Commands that print outputGuarded by an interactive checkOutput breaks scp, sftp and rsync
Long-running commandsNowhereThey 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.

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

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

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. .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
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 → .bashrc. 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
bashrc~/.bashrcbash startup fileinteractive bash config
Embedded reference data

Quick lookup tables

.bashrc operational reference

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

Lookup boundaryTopic-specific referenceOperational 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 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 chainBash invocation mode → system startup files → ~/.bashrc eligibility/source order → conditionals/definitions → effective shell variables/functions/aliases/options → command behaviorTrace 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 evidenceCorrelated 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 behaviorUse 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. .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 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.

.bashrc · operational reference

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

Reference boundary.bashrc
Topic pathShell & 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 chainBash 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 ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?