After starting a bash terminal, I noticed that the PATH variable contains duplicate entries. My terminal starts a login shell, so ~/.bash_profile is sourced, followed by ~/.profile and ~/.bashrc. Only in ~/.profile do I create the paths entries which are duplicated.To be pedantic, this is the order in which the files that SHOULD be sourced are being sourced:Sourced /etc/profileSourced /etc/bash.bashrcSourced .bash_profileSourced .profileSourced .bashrcBefore anyone marks this as a duplicate of PATH variable contains duplicates, keep reading.At first I thought this had to do with ~/.profile being sourced twice, so I had the file write to a log file whenever it was sourced, and surprisingly it only logged one entry, which tells me that it was only sourced once. Even more surprising is the fact that when I comment out the entries which were in ~/.profile, the entries still appear in the PATH variable. This has led me to three conclusions, one of which was quickly ruled out:Bash ignores valid bash comments and still executes the commented codeThere is a script which reads the ~/.profile and ignores any code that prints an output (the log file for example)There is another copy of my ~/.profile which is being sourced elsewhereThe first one, I quickly concluded not to be the case due to some quick testing. The second and third options are where I need help with.How do I gather a log of scripts which are executed when my terminal starts up? I used echo in the files that I checked to know if they are sourced by bash, but I need to find a conclusive method which traces the execution up the point when the terminal is ready for me to start typing into it.If the above is not possible, then can anyone suggest where else I can look to see which scripts are being run
Find out what scripts are being run by bash on startup
bash;profile
If your system has strace then you can list the files opened by the shell, for example usingecho exit | strace bash -li |& less | grep '^open'(-li means login shell interactive; use only -i for an interactive non-login shell.)This will show a list of files which the shell opened or tried to open. On my system, they are as follows:/etc/profile/etc/profile.d/* (various scripts in /etc/profile.d/)/home/<username>/.bash_profile (this fails, I have no such file)/home/<username>/.bash_login (this fails, I have no such file)/home/<username>/.profile/home/<username>/.bashrc/home/<username>/.bash_history (history of command lines; this is not a script)/usr/share/bash-completion/bash_completion/etc/bash_completion.d/* (various scripts providing autocompletion functionality)/etc/inputrc (defines key bindings; this is not a script)Use man strace for more information.