/etc/profile is the system-wide .profile file for the Bourne shell and Bourne compatible shells
- On ubuntu, the
PATHenvironment variable is being set in/etc/environmentand addition can be set in/etc/profile. This one references/etc/bash.bashrcand every readable files in/etc/profile.d. - On mac OS,
/usr/libexec/path_helperis beeing exectued for setting the$PATHenvironment variable, then/etc/bashrcand 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
fimacOS 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