Skip to content

Instantly share code, notes, and snippets.

@e-roux
Last active September 20, 2020 15:39
Show Gist options
  • Select an option

  • Save e-roux/4654e41eace42cf4b539c2c4f21fd9f9 to your computer and use it in GitHub Desktop.

Select an option

Save e-roux/4654e41eace42cf4b539c2c4f21fd9f9 to your computer and use it in GitHub Desktop.
Memo: shell startup

/etc/profile

/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 /etc/environment and addition can be set in /etc/profile. This one references /etc/bash.bashrc and every readable files in /etc/profile.d.
  • 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

macOS

# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment