{"id":2482,"date":"2020-04-08T00:14:03","date_gmt":"2020-04-08T04:14:03","guid":{"rendered":"https:\/\/wls.wwco.com\/blog\/?p=2482"},"modified":"2020-04-08T09:56:05","modified_gmt":"2020-04-08T13:56:05","slug":"bash-and-paths-on-macos","status":"publish","type":"post","link":"https:\/\/wls.wwco.com\/blog\/2020\/04\/08\/bash-and-paths-on-macos\/","title":{"rendered":"Bash and Paths on macOS"},"content":{"rendered":"\n<p>I was helping a friend diagnose why a strange script-like string was appearing <em>in<\/em> their PATH whenever they logged in or created a new&nbsp;<a href=\"https:\/\/www.gnu.org\/software\/bash\/\">bash<\/a> shell window. (Note: Catalina now defaults to using <a href=\"https:\/\/www.zsh.org\">zsh<\/a>, not bash.)<\/p>\n<p>Bash has a number of different configuration files it checks, and some of those the user may have chained together. So far, even <a href=\"https:\/\/shreevatsa.wordpress.com\/2008\/03\/30\/zshbash-startup-files-loading-order-bashrc-zshrc-etc\/\">the best resource on the matter I&#8217;ve found<\/a> doesn&#8217;t tell the whole story.<\/p>\n<p>On Apple machines, bash walks through&nbsp;<em>these<\/em> set of scripts and invokes a path modification tool, too.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"676\" src=\"https:\/\/wls.wwco.com\/blog\/wp-content\/uploads\/2020\/04\/Bash-and-Paths-on-macOS-3-1024x676.png\" alt=\"\" class=\"wp-image-2487\" srcset=\"https:\/\/wls.wwco.com\/blog\/wp-content\/uploads\/2020\/04\/Bash-and-Paths-on-macOS-3-1024x676.png 1024w, https:\/\/wls.wwco.com\/blog\/wp-content\/uploads\/2020\/04\/Bash-and-Paths-on-macOS-3-300x198.png 300w, https:\/\/wls.wwco.com\/blog\/wp-content\/uploads\/2020\/04\/Bash-and-Paths-on-macOS-3-768x507.png 768w, https:\/\/wls.wwco.com\/blog\/wp-content\/uploads\/2020\/04\/Bash-and-Paths-on-macOS-3.png 1150w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption><em>macOS Bash Scripts and Path Modifications (validated with macOS Mojave v10.14.6 on 2020-04-08)<\/em><\/figcaption><\/figure>\n\n\n\n<p>In a nutshell, <code>\/etc\/profile<\/code> calls a utility called <code>path_helper<\/code>, and it reads a list from two places the <code>\/etc\/paths<\/code> file and <em>everything<\/em> in the <code>\/etc\/paths.d<\/code> directory.<\/p>\n\n\n\n<p>My friend had thought the <code>\/etc\/paths<\/code> file was a <em>script<\/em> and not a <em>list<\/em>, and years ago had erroneously put an <code>export PATH=<\/code> statement in there. Because it came last (for his setup), he ignored the problem.<\/p>\n\n\n\n<p>Our false start to correct is was upon seeing an export statement <em>in the PATH itself<\/em>, we assumed it was a faulty quoting problem in a script, so primarily went looking in the <em>script <\/em>files on the left side of the graph &#8230;and wasted what felt like hours doing so.<\/p>\n<p>Only after using Bash&#8217;s <code>return<\/code> statement to short-circuit script executions and using a blunt hammer of renaming scripts out of execution&#8217;s way, and the problem\u00a0<em>still<\/em> persisted, did deeper exploration go down the\u00a0<em>system<\/em> resources.<\/p>\n<p>I hope this diagram helps get others out of trouble.<\/p>\n<hr \/>\n<p>UPDATE 2020-07-08: Bob Rudis caught a typo (the text said \/etc\/profile, where it should have said \/etc\/paths); he also shared a link to <a href=\"https:\/\/www.gnu.org\/software\/bash\/manual\/html_node\/Bash-Startup-Files.html\">GNU&#8217;s Bash Startup Files<\/a>.<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>On macOS, there&#8217;s a little more than just the order of bash scripts messing with your path. Here&#8217;s an updated diagram showing the inside scoop.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47,62,79,81],"tags":[1029,1028,718],"class_list":["post-2482","post","type-post","status-publish","format-standard","hentry","category-apple","category-geek","category-operating-systems","category-os-x","tag-bash","tag-macos","tag-path"],"_links":{"self":[{"href":"https:\/\/wls.wwco.com\/blog\/wp-json\/wp\/v2\/posts\/2482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wls.wwco.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wls.wwco.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wls.wwco.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/wls.wwco.com\/blog\/wp-json\/wp\/v2\/comments?post=2482"}],"version-history":[{"count":4,"href":"https:\/\/wls.wwco.com\/blog\/wp-json\/wp\/v2\/posts\/2482\/revisions"}],"predecessor-version":[{"id":2492,"href":"https:\/\/wls.wwco.com\/blog\/wp-json\/wp\/v2\/posts\/2482\/revisions\/2492"}],"wp:attachment":[{"href":"https:\/\/wls.wwco.com\/blog\/wp-json\/wp\/v2\/media?parent=2482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wls.wwco.com\/blog\/wp-json\/wp\/v2\/categories?post=2482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wls.wwco.com\/blog\/wp-json\/wp\/v2\/tags?post=2482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}