0

I need to accurately know the order in which scripts are run for an interactive login shell. The order I "think" it runs is below, but I'm definitely unsure of its accuracy and would like someone to confirm the correct order:

1./etc/profile , which then executes scripts in /etc/profile.d/*
2./etc/profile then executes ~/.bash_profile
3.~.bash_profile then invokes ~./bashrc
4.~/.bashrc then loads /etc/bash.bashrc

Secondly, I want someone to confirm the order in which bash scripts are run for interactive non-login shells. Thus far I have it written down as:

1.~/.bashrc , which then loads /etc/bash.bashrc

Note: Although similar questions have been asked on this forum before, those answers do not go into the depth I'm looking for to answer this question (they usually stop after it talks about loading .bash_profile)

1

I will not answer directly but give you the tool to find your answer.

First, you need to read the bash man page, or your shell man page. This will tell you explicitly in what order the configuration script are run, be it a login or not, an interactive shell or not, etc ...

Secondly, you can always find it by experimenting yourself. In each script, you can run whatever command you like. So for exemple, you can add yourself a line like

echo "$$: Inside /etc/profile" >> /tmp/test_for_unstanding_bash_script_order.log

inside /etc/profilefor example. $$ stands for the PID of the running shell.

Then you do the same for all the other files by changing the string written to the log.

Then you go and look inside that log file in what order are the lines.

Then you have to undo your changes.

So here is what I got myself, when I add those lines:

For a login shell:

8724: Inside /etc/bash.bashrc
8724: Inside /etc/profile.d/01-locale-fix.sh
8724: Inside /etc/profile.d/apps-bin-path.sh
8724: Inside /etc/profile.d/bash_completion.sh
8724: Inside /etc/profile.d/cedilla-portuguese.sh
8724: Inside /etc/profile.d/vte-2.91.sh
8724: Inside /etc/profile.d/xdg_dirs_desktop_session.sh
8724: Inside /etc/profile
8724: Inside ~/.bashrc

Note: I have added the echo line at the end of each file. This could give a wrong order. Especially in /etc/profile. So in /etc/profile, put the line at the top.

| improve this answer | |
  • So what your saying is that your on a forum where people have questions that they would like to be answered, and your unwilling to answer them? FYI, I've read the bash man page, and this also stops at the bash_profile section, which is the reason for the creation of this post. Would really appreciate it if you do know the answer, to simply answer it. I would be most grateful. I've just spent 2 hours reading around this topic, so it's not like I'm one for not trying. It just seems like your being unnecessarily difficult. I've also experimented and found that my variable always loads! – john smith Mar 23 '19 at 15:38
  • To add to my note above. I created a variable in each of the places where bash can pull its scripts from, and with my login shell it loaded from any of those places. EG, I make a variable called test1 in /etc/profile, and make test2 in /etc/bash.bashrc. Each time, it loads. So I am sure it must be loading those scripts, but the what order is unclear. So as I say, if you know the answer, please just give it. I've spent an unnecessary amount of time trying to figure this out. – john smith Mar 23 '19 at 15:44
  • @johnsmith please incorporate your comment on what you've tried into your question. – DK Bose Mar 23 '19 at 15:48
  • What would be the point? I want to keep my question clear and concise, which is precisely what I've managed to do. By adding all of the things I've tried to figure out by myself into the post, it simply clogs it up with junk that has no relevance to the question I want to ask. – john smith Mar 23 '19 at 16:22
  • @johnsmith I am sorry to see you did not take my answer as an answer. I did not know the answer, but I did know how to find it. I did what I told you, and I got the answer in less than 10 minutes. – solsTiCe Mar 23 '19 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.