Is there a way in Bash to view which "dot files" were loaded, and in what order they were loaded in?
I'm trying to authoritatively figure out which Bash profile files were loaded, and what order they were loaded in, on Mac OS X.
I wouldn't know how to determine this dynamically, on any given OS X system, without any preparatory work.
However, with preparatory work as an option, Etan Reisner and twalberg offer helpful options in their comments:
Trace the files that bash opens when a new shell is created - see below.
If you know the set of candidate files, edit each and put something like echo "Loading file <filename>..." at the top.
man bash should list all candidate files/etc/profile on OS X loads non-standard file /etc/bashrc, which in turn (since OS X 10.11) loads /etc/bashrc_Apple_Terminal.Tracing the files opened by a bash shell during startup:
opensnoop is a shell script wrapper around the dtrace utility that comes with OS X and that you can use as follows:
Caveat (tip of the hat to 4ae1e1): With the introduction of SIP (System Integrity Protection) in OS X 10.11, opensnoop no longer works with executables in system locations such as /bin/, /sbin/ and /usr/bin, which includes bash.
DTrace - and thus opensnoop - can be made to work in these locations, but only if you boot into the recovery partition, select Utilities > Terminal, and execute
csrutil enable --without dtrace there; note, however, that you'll get the following dire warning: csrutil: requesting an unsupported configuration. This is likely to break in the future and leave your machine in an unknown state.
A pragmatic workaround is to copy /bin/bash to a user-specific location and execute it from there - see below.
sudo opensnoop -n bash in an existing Terminal window.bash instance.
invalid user access in action ... error messages you're seeing initially.bash executable to a location other than /bin/, /sbin/ or /usr/bin - such as to ~ - launch it with ~/bash -l, which emulates how Terminal.app creates a new instance (it creates an interactive logon shell).opensnoop command:
-1 in the FD column, which tells you which files bash tries to open, and in what order; note that in the case of the ~/.bash_profile, ~/.bash_login and ~/.profile troika only the first one that actually exists is opened.Example output from a pristine OS X 10.10 system:
UID PID COMM FD PATH
501 5110 bash 3 /dev/dtracehelper
501 5110 bash 3 /dev/tty
501 5110 bash 3 /usr/share/locale/en_US.UTF-8/LC_COLLATE
501 5110 bash 3 /usr/share/locale/en_US.UTF-8/LC_CTYPE
501 5110 bash 3 /usr/share/locale/en_US.UTF-8/LC_MONETARY
501 5110 bash 3 /usr/share/locale/en_US.UTF-8/LC_NUMERIC
501 5110 bash 3 /usr/share/locale/en_US.UTF-8/LC_TIME
501 5110 bash 3 /usr/share/locale/en_US.UTF-8/LC_MESSAGES/LC_MESSAGES
501 5110 bash -1 /etc/.mdns_debug
501 5110 bash 3 /etc/profile
501 5110 bash 3 /etc/bashrc
501 5110 bash -1 /Users/jdoe/.bash_profile
501 5110 bash -1 /Users/jdoe/.bash_login
501 5110 bash -1 /Users/jdoe/.profile
501 5110 bash 3 /Users/jdoe/.bash_history
501 5110 bash 3 /Users/jdoe/.bash_history
501 5110 bash 3 /usr/share/terminfo/78/xterm-256color
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With