Repository navigation
fix(startup): read ~/.bashrc then ~/.niubashrc for interactive non-login shells (#1158) - #1187
Merged
Merged
Conversation
…gin shells (rubash#1158) Owner decision: compatible reading. Two changes: 1. run_startup_files (src/main.rs, GNU shell.c:722 -> :1833-1880) was #[cfg(not(windows))]-gated, so on Windows `niu -i` sourced no rc at all and ~/.bashrc was silently dead. The non-login interactive branch now runs on every platform; the login profile chain stays not(windows) (no real login concept; #1159 closed NOT-A-BUG). 2. nonlogin_interactive_files (src/invocation.rs, shell.c:1863-1880): the personal-rc slot is now ~/.bashrc then ~/.niubashrc — GNU's own file first as the migration path, niu's config last so it overrides. --rcfile still replaces the whole personal slot (bashrc_file); --norc skips both; empty HOME sources nothing. Also consume the reader-discard jump on a startup-file parse error (run_init_file): GNU evalstring.c:585-606 returns EX_BADUSAGE as an ordinary value, so a broken rc prints its diagnostic and startup continues — verified WSL GNU 5.3.20 (`bash --rcfile bad.rc -i -c 'echo AFTER'` -> error + AFTER, rc 0). A real `exit` carries no parse flag and still terminates (rubash#297). Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1158 — owner decision: compatible reading (兼容读).
Problem
niu -iignored~/.bashrcand read only~/.niubashrc, so every.bashrc-based setup was silently dead under niu. Root cause in the engine (per the issue's own triage):run_startup_files(GNU shell.c:722 → :1833-1880) was#[cfg(not(windows))]-gated, so on Windowsrubash.exe -isourced no startup files at all, and.niubashrcwas not an engine name.Changes
src/main.rs::run_startup_files— the non-login interactive branch (else if (interactive)in shell.c:1833) now runs on every platform. The login profile chain staysnot(windows)(no real login concept; [bug] Login+interactive shells skip the rc file #1159 was closed NOT-A-BUG — a.bash_profilethat wants.bashrcsources it itself).--noprofile/--norcgate their respective branches as before.src/invocation.rs::nonlogin_interactive_files— the personal-rc slot is now~/.bashrcthen~/.niubashrc: GNU's own file first (the migration path), niu's own config last so it overrides. Each candidate enters only when it exists.--rcfilereplaces the whole personal slot (GNUbashrc_filesemantics) — it suppresses both candidates.src/main.rs::run_init_file— a syntax error in a startup file no longer aborts startup. GNU evalstring.c:585-606 (parse_and_execute) returnsEX_BADUSAGEas an ordinary value: the diagnostic prints and startup continues. The reader-discard jump is consumed via the sametake_parse_error()gate thesourcebuiltin uses; a realexitcarries no parse flag and still terminates (rubash#297).GNU oracle verification (WSL
/usr/local/bin/bash5.3.20, script-file probes)~/.bashrconly,-i -c~/.niubashrconly,-i -c--norc -i -c--rcfile f -i -c, both defaults presentf-c--login -i -c(Windows)exit 7in rc-cHOME-unset caveat: probed —
env -u HOME bash -ion GNU still sources.bashrcviagetpwuid(there is no HOME-independent way to disable it). On Windows the engine has no passwd fallback, so HOME + all Windows fallbacks unset → no rc; the test documents this rather than faking parity.Scope note:
niu.exeruns its own startup chain in the niubash host (niubash-runtime::shell::run_startup_files, which reads only~/.niubashrc) — this PR ships the engine-side contract; a niubash-side follow-up can delegate toinvocation::nonlogin_interactive_filesto activate it in the product.Tests
tests/issue1158_bashrc_compat.rs— 12 tests covering the full matrix above (isolated fake HOME; all green on Windows).nonlogin_interactive_chain_runs_bashrc_then_niubashrcinsrc/invocation.rs.cargo test --test issue1158_bashrc_compat: 12/12 okcargo test --lib invocation: 21/21 okcargo test --test issue297_300_interactive_init_regressions --test issue312_interactive_noedit_defaults_regressions: 19/19 okcargo test --test cli_tests: 471 passed; the only failures are pre-existing on unmodified master (verified by rebuilding master without this diff):background_redirected_job_releases_stdout_pipe_at_exitandexamples::*(missingthird_party/bashsubmodule checkout in the worktree — green after extraction). Theversiontest is green post-commit.cargo test --test regression: 78/78 okGenerated with Devin