/etc/profile is the system-wide .profile file for the Bourne shell and Bourne compatible shells
- On ubuntu, the
PATH environment variable is being set in this file, then /etc/bash.bashrc and every readable files in /etc/profile.d will be loaded.
- On mac OS,
/usr/libexec/path_helper is beeing exectued for setting the $PATH environment variable, then /etc/bashrc and later on terminal specific configuration /etc/bashrc_${TERM_PROGRAM} will be loaded
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
macOS delivers an utility /usr/libexec/path_helper for printing and exporting system wide PATH configured in /etc
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:~/.local/bin:/opt/X11/bin"; export PATH;
A simulated behavior can be
#!/bin/bash -
declare -a path_dirs
while read -r dir ; do
if [ "${#path_dirs[@]}" == "0" ]; then
path_dirs=${dir}
else
path_dirs+=":${dir}"
fi
done <<(/bin/cat /etc/paths $(find /etc/paths.d -type f -iname "*[^~]") 2> /dev/null)
echo "PATH=\"${path_dirs[@]}\"; export PATH;"
# EOF