-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
bash: user's ~/.bashrc shouldn't be sourced in system bash.bashrc #7981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Sourcing ~/.bash_profile / ~/.profile before ~/.bashrc makes sense, and from testing this I don't notice any issues. I don't really have a good grasp of what order, and how, the various profile and rc files are suppose to be sourced, so I would like to get a second approval opinion here (or time for me to read bash's documentation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, .bashrc
has to be sourced after ~/.bash_profile
. However Bash in interactive login mode doesn't load ~/.bashrc
on its own. That's why Termux sources it in profile.
I can propose creating default .bashrc
and .bash_profile
scripts packaged as part of termux-tools
package and modify login
script (also part of termux-tools
) to copy them to $HOME
if they do not exist.
.bash_profile
should contain at least this:
[ -f "${HOME}/.bashrc" ] && . "${HOME}/.bashrc"
Some distributions source the ~/.bashrc
in /etc/profile
. E.g. that's what I have on OpenSUSE installation:
if test -z "$_SOURCED_FOR_SSH" -a "$norc" != true ; then
#
# System BASH specials, maybe also good for other shells
# Note that ksh always reads /etc/ksh.kshrc
#
if test "$is" != ksh -a "$is" != zsh ; then
_is_save=$is
test -r /etc/bash.bashrc && . /etc/bash.bashrc
is=$_is_save
unset _is_save
fi
if test "$restricted" = true ; then
readonly _HOMEBASHRC=true
fi
if test "$is" = "bash" -a -z "$_HOMEBASHRC" ; then
# loop detection
readonly _HOMEBASHRC=true
test -r $HOME/.bashrc && . $HOME/.bashrc
fi
I was gonna post the comment yesterday but got busy with some other stuff to complete it. If we are going to be changing the behaviour of startup files, best think on this from a future perspective as well. The behaviour would depend on distros of course, but the debian/ubuntu defaults are below. The following are provided by the The following are provided by the modified
The You can check the invocation order in The
Only the first file in
I don't think these changes should affect any "systemd" implementation that is done in termux app in future. Systemd does not run any startup files and has its own environment files. https://unix.stackexchange.com/a/455283 |
What I'm proposing is to just provide bootstrap rc files (like /etc/skel on Linux distributions) that will be placed into $HOME on first login or if not exist, in addition to fix order. However rc files, whether this is
Yes, it should be login shell for every opened terminal as we don't have other way to "log in". On Linux distribution login shell is started when user logged in through TTY console or SSH and terminal emulators start the non-login shell by default. |
Agreed, this should be https://sources.debian.org/src/base-files/11.1+deb11u1/share/dot.profile/#L5
Yeah, already get all that... I was just talking from the perspective of login shell stuff being run every time. Do plan on exporting an |
This issue/PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This PR seems to be 2.5 years old. Should we keep it open or we can close it? |
Will need to be eventually worked on, so fine to keep open. |
Loading the bashrc from the system profile is problematic because it invokes the bashrc before the environment from the user profile is loaded. Conditionally sourcing the bashrc should happen from the user profile, which can be deployed to user homes via the /etc/skel mechanism. |
Bash doesn't load the bashrc for interactive login shells. As work-around for that, the bashrc is sourced by the user profile. This is both debian default and my behavior. Termux put the code incorrectly into the *global* profile, resulting in the bashrc being invoked before the user profile has loaded. With ENV not being set, the bashrc throws an error. Work-around until termux/termux-packages#7981 is merged and shipped.
Sourcing user's rc-file in system profile causes calling init files in the wrong order:
$PREFIX/etc/profile
$PREFIX/etc/bash.bashrc
~/.bashrc
~/.bash_profile
or~/.profile
While the
~/.bash_profile
or~/.profile
should be called before the~/.bashrc
.With this PR merged, a non-login interactive shell will load the
~/.bashrc
anyway, and for login shell user can source it in the~/.bash_profile
or~/.profile
. The current behavior forces to make workarounds in the user's init files.Also, it looks like the majority of Linux distros don't source user's rc-file in system profile-file.