2.6 KiB
2.6 KiB
Plan: Hacer que .bashrc cargue variables de entorno en shells no interactivos
Context
The .bashrc file has an early-exit guard at lines 5-9:
case $- in
*i*) ;;
*) return;;
esac
This causes bash to skip the entire file when invoked in non-interactive mode (scripts, bash -c "...", CI, Docker exec). All the export statements at the bottom of the file (PATH, JAVA_HOME, ANDROID_HOME, NVM, SDK, tokens) are therefore never loaded in non-interactive shells.
The .profile sources .bashrc, but .profile is only read by login shells. So login shells get the exports (via .profile → .bashrc), but non-interactive shells do not.
Solution
Move the environment variable exports above the interactive guard so they are always sourced, regardless of shell mode. Keep interactive-only content (aliases, prompt, history, completion) below the guard.
File to modify
/home/aleleba/projects/aleleba-vscode-dockerfile-configuration/.bashrc(also copied to~/.bashrcby entrypoint.sh)
Changes
- Keep the guard at the top — it stays, but only guards interactive-only content.
- Move all
exportstatements above the guard:export LS_COLORS=...export PATH=...(includes Java, Android SDK, NVM paths)export JAVA_HOME=...export ANDROID_HOME=...export ANDROID_SDK_ROOT=...export NVM_DIR=...+nvm.shsource +nvm use defaultexport EMSDK_QUIET=...source /emsdk/emsdk_env.shexport PATH="$HOME/.local/bin:$PATH"- All token/credential exports (
GITEA_TOKEN,GMAIL_ADDRESS,NPM_TOKEN,SUPABASE_ACCESS_TOKEN, etc.)
- Keep everything else below the guard (aliases, prompt, history, completion, dircolors, etc.) — these are interactive-only and should not run in scripts.
- Keep
.profileas-is — it sources.bashrc, which will now correctly load exports even in login shells.
Result
| Shell type | Exports loaded? | Aliases/prompt loaded? |
|---|---|---|
| Interactive login | Yes (via .profile → .bashrc) |
Yes |
| Interactive non-login | Yes (direct .bashrc source) |
Yes |
Non-interactive (bash -c, scripts, CI) |
Yes (exports are above guard) | No (correct) |
Verification
bash -c 'echo $JAVA_HOME $ANDROID_HOME $NVM_DIR'— should print valuesbash -c 'echo $GITEA_TOKEN'— should print the tokenbash -c 'alias ll'— should fail (aliases not loaded in non-interactive, correct)bash -i -c 'alias ll'— should work (interactive still gets aliases)- Build and run the Docker container, exec into it and check
printenv | grep -E 'JAVA|ANDROID|NVM|PATH'