Skip to content

fix: stop ~/.bashrc early in non-interactive shells - #37

Merged
JtheGunner merged 2 commits into
mainfrom
fix/non-interactive-bashrc-guard
Nov 23, 2026
Merged

JtheGunner merged 2 commits into
mainfrom
fix/non-interactive-bashrc-guard

Conversation

@JtheGunner

Copy link
Copy Markdown
Owner

Problem

bash reads ~/.bashrc for every ssh command. Since bootstrap.sh puts the rc libraries into it, a non-interactive session loaded them too. On hosts where sudo needs a password this broke Ansible: its become prompt detection ran into Timeout (12s) waiting for privilege escalation prompt as soon as bootstrap.sh had run for the ssh user (seen while rolling the dotfiles out to Proxmox guests, INFRA-38). With case $- in *i*) ;; *) return;; esac at the top of the file it works again.

Change

The dotfiles:base block written to ~/.bashrc now returns early unless the shell is interactive:

# >>> dotfiles:base >>>
export DOTFILES="..."
case $- in *i*) ;; *) return ;; esac
[ -r "$DOTFILES/bash/bashrc.bash" ] && . "$DOTFILES/bash/bashrc.bash"
# <<< dotfiles:base <<<

~/.zshrc is unchanged (zsh reads it only for interactive shells). DOTFILES is still exported first, and the DOTFILES= line that the checkout detection parses stays in the same place.

Existing base blocks are not rewritten: a run that finds the block already present still skips it. A machine that already ran bootstrap.sh gets the guard when its ~/.bashrc is regenerated or the line is added by hand.

Test plan

  • New tests/test-bashrc-noninteractive.sh: guard present in .bashrc and absent in .zshrc, placed after the DOTFILES export; a non-interactive bash -c '. ~/.bashrc' does not load the library, an interactive bash -ic does.
  • for t in tests/test-*.sh; do bash $t; done: all pass locally.
  • shellcheck was not available locally; CI runs make lint.

bash reads ~/.bashrc for every ssh command. Loading the rc libraries there breaks callers that expect a quiet shell: Ansible's become prompt detection timed out on hosts whose sudo needs a password once bootstrap.sh had run. The bash base block now returns early unless the shell is interactive; the zsh block is unchanged because zsh reads ~/.zshrc only interactively. Existing base blocks are left as they are.
@JtheGunner
JtheGunner merged commit 2187627 into main Nov 23, 2026
10 of 13 checks passed
@JtheGunner
JtheGunner deleted the fix/non-interactive-bashrc-guard branch November 23, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant