#15403: inject shell rc contents to none interactive shells BUG #9302
gateway
stale
size: S
This fixes errors produced due to shell rc content not being loaded for none interactive shells. https://github.com/openclaw/openclaw/issues/15396
ex.
System: [2026-02-13 18:25:53 GMT+7] Cron: ⚠️ 🛠️ Exec: cd ~/.openclaw/workspace && python - <<'PY' failed: zsh:1: command not found: python
I don't believe creating a symlink to patch the underline issue is not the right solution. This approach will improve the usability of the product for a larger audience.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a `buildEnvDumpCommand()` function that generates shell-specific RC-sourcing commands before running `env -0` to dump the environment. Previously, both `loadShellEnvFallback` and `getShellPathFromLoginShell` ran `env -0` in a login shell (`-l`), which loads profile files (`.bash_profile`, `.zprofile`) but skips interactive RC files (`.bashrc`, `.zshrc`) where tools like pyenv/nvm/rbenv commonly set PATH. This caused "command not found" errors for tools configured in RC files when running in non-interactive contexts (e.g., cron jobs).
The new function handles zsh, bash, fish, ksh variants, tcsh/csh, nushell, elvish, xonsh, and pwsh/powershell, with a POSIX-compatible fallback for unknown shells. Tests are comprehensive and cover all shell variants plus integration tests verifying the command is passed through to `exec`.
- Adds `buildEnvDumpCommand()` with a `switch` on `path.basename(shell)` to map shells to their RC-sourcing commands
- Replaces the hardcoded `"env -0"` string in both `loadShellEnvFallback` and `getShellPathFromLoginShell` with `buildEnvDumpCommand(shell)`
- Adds thorough unit tests for all shell variants and integration tests that verify the full `exec` call arguments
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — it adds well-guarded RC sourcing with error suppression across all shell types, and all commands fail gracefully via existing try/catch blocks.
- Score of 4 reflects: solid implementation with appropriate error handling for each shell type, comprehensive test coverage, no critical logic bugs found. The only concern is that the default fallback sources `.bashrc`/`.zshrc` inside unknown shells (e.g., dash), which could partially execute bash-specific syntax — but this is a minor risk mitigated by `|| true` and the surrounding try/catch, and was already discussed in prior review threads.
- No files require special attention — the implementation and tests are well-aligned.
<sub>Last reviewed commit: 94a6de4</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#11961: fix: exec tool wraps shebang scripts in heredoc to use correct inte...
by scott-memco · 2026-02-08
73.0%
#6382: fix(cli): silence Powerlevel10k Zsh warning from completion script
by dungngo4520 · 2026-02-01
72.8%
#11300: feat(exec): make shell configurable via tools.exec.shell
by imjszhang · 2026-02-07
72.3%
#18003: feat(infra): Adaptive SSH Environment Wrapper (ARE)
by stakeswky · 2026-02-16
72.3%
#17437: fix(completion): avoid rc=1 for optionless zsh leaf commands
by ephelia-ai · 2026-02-15
72.0%
#20640: fix: prevent zsh glob expansion errors in exec commands
by okuyam2y · 2026-02-19
71.8%
#12871: fix: use bash and warn about shell injection (issue #12836)
by ambicuity · 2026-02-09
71.6%
#9148: Fix: Speed up shell completion generation from ~4.6s to <200ms
by vishaltandale00 · 2026-02-04
71.1%
#12308: fix(cli): redirect log output to stderr during completion script ge...
by mcaxtr · 2026-02-09
71.0%
#9200: Fix: Strip dangerous env vars from baseEnv in host execution
by vishaltandale00 · 2026-02-05
70.5%