Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. # `/etc/profile`
  2.  
  3. `/etc/profile` is the system-wide `.profile` file for the Bourne shell and Bourne compatible shells
  4.  
  5. - 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.
  6. - 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
  7.  
  8.  
  9. ## macOS
  10.  
  11. ```bash
  12. # System-wide .profile for sh(1)
  13.  
  14. if [ -x /usr/libexec/path_helper ]; then
  15. eval `/usr/libexec/path_helper -s`
  16. fi
  17.  
  18. if [ "${BASH-no}" != "no" ]; then
  19. [ -r /etc/bashrc ] && . /etc/bashrc
  20. fi
  21. ```
  22.  
  23. macOS delivers an utility `/usr/libexec/path_helper` for printing and exporting system wide PATH configured in `/etc`
  24.  
  25. > PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:~/.local/bin:/opt/X11/bin"; export PATH;
  26.  
  27. A simulated behavior can be
  28.  
  29. ```bash
  30. #!/bin/bash -
  31.  
  32. declare -a path_dirs
  33.  
  34. while read -r dir ; do
  35. if [ "${#path_dirs[@]}" == "0" ]; then
  36. path_dirs=${dir}
  37. else
  38. path_dirs+=":${dir}"
  39. fi
  40. done <<(/bin/cat /etc/paths $(find /etc/paths.d -type f -iname "*[^~]") 2> /dev/null)
  41.  
  42. echo "PATH=\"${path_dirs[@]}\"; export PATH;"
  43.  
  44. # EOF
  45. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement