Where are the PATH configuration files?

I've searched my entire hard drive for hidden and system files with names containing "bash" or "profile." I find only one: .profile, in my home directory. It was installed by MacPorts and contains 2 paths: /opt/local/bin and /opt/local/sbin. These are the first 2 that appear in PATH when I issue a "set" to see my current environment.

But PATH shows 6 more: usr/bin, /bin, /usr/sbin, /sbin, /usr/local/bin, and /usr/X11/bin. I presume these paths are set by a login configuration file, and perhaps others.

Will someone tell me what they're named and where they are please? (Sorry for the newbie question -- I did a search and couldn't find an answer here.)

iMac G4 20" USB 2.0, 1.25 GHz 1.5/160 GB, Mac OS X (10.5.8), AE 5.7, AX 6.3, AE card 405.1 (all b/g)

Posted on Mar 2, 2011 2:03 PM

Reply
12 replies

Mar 2, 2011 4:07 PM in response to Dave Post

Dave Post wrote:
PATH shows 6 more: usr/bin, /bin, /usr/sbin, /sbin, /usr/local/bin


Its in the file "paths" in /etc

and /usr/X11/bin


This is in the file X11 in /etc/paths.d

from; man path_helper:

The path_helper utility reads the contents of the files in the directo-
ries /etc/paths.d and /etc/manpaths.d and appends their contents to the
PATH and MANPATH environment variables respectively. (The MANPATH envi-
ronment variable will not be modified unless it is already set in the
environment.)
Files in these directories should contain one path element per line.
Prior to reading these directories, default PATH and MANPATH values are
obtained from the files /etc/paths and /etc/manpaths respectively.
NOTE
The path_helper utility should not be invoked directly. It is intended
only for use by the shell profile.

Mar 2, 2011 2:24 PM in response to Dave Post

/etc/profile


# System-wide .profile for sh(1)
PATH="/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin"
export PATH
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi


from the bash manpage:


When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it
first reads and executes commands from the file /etc/profile, if that file exists. After reading that file,
it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands
from the first one that exists and is readable. The --noprofile option may be used when the shell is started
to inhibit this behavior.


Message was edited by: Nils C. Anderson

Mar 2, 2011 6:42 PM in response to Dave Post

Will someone tell me what they're named and where they are please?

A more important question from our perspective, is "what are your intentions?"

If it is just education, then Tony T1 has the correct information,
with Nils C. Anderson getting credit for pointing out /etc/profile (even if he has been modifying his copy 🙂 ).

If your intention is to change your PATH, then a lot depends on the ultimate goal.

The typical approach is to change $HOME/.bash_profile, however, since bash supports alternate initializations it will look for the following files and select the first one it finds

.bash_profile
.bash_login
.profile

Since MacPorts has already established .profile, if you intend to add/remove paths from your PATH environment variable, then $HOME/.profile is the place to do that as well as other bash initializations.

Editing /etc/profile, or one of the /etc/paths.d entries may be lost on a system upgrade, or when migrating to a new system where only your $HOME directory is preserved.

However, there are situations where editing something more global is called for, which is why I'm asking your intentions, if only to get you heading down the right PATH (pun intended 🙂 ).

Mar 3, 2011 6:54 AM in response to BobHarris

I love these forums. I almost always get quick, informed, patient responses like these. Thank you all very much.
Nils C. Anderson wrote:

/etc/profile

I'm stumped as to why my search didn't find that profile. Whatever mistake I made, I did it more than once. As for its content, mine matches Tony's and Bob's.

BTW, I'd love to see your AppleScript for formatting UNIX scripts properly in these forums. I have one that works ordinarily, but it appears that the brackets that can appear in UNIX scripts cause mine to add unwanted strikeouts and font-color changes.
Tony T1 wrote:

Its in the file "paths" in /etc

<snip>
This is in the file X11 in /etc/paths.d

Yup, although, on my 10.5.8 system, /etc is an alias to /private/etc.
from; man path_helper:

Doh! I should have done a man -k path before posting. Sorry.
BobHarris wrote:

A more important question from our perspective, is "what are your intentions?"
If it is just education, then Tony T1 has the correct information

<snip>
If your intention is to change your PATH, then a lot depends on the ultimate goal.

It's a little of both. I've been trying to learn more about UNIX via the exercise of creating a universal binary, using code from an open-source project. Their configure script is failing to find some files and, although I realize the best solution is probably to just "export" some temporary paths to them, it got me wondering where the default paths are kept. The 2 UNIX books I've been studying misdirected me.

Thanks for your succinct tutorial. It's helped me understand how to handle paths in Darwin much better.

Is there a good book that focuses on Darwin -- especially one that covers scripting fairly thoroughly? I've done a bit of coding in my time, but some of the scripting syntax baffles me.

Mar 3, 2011 8:16 AM in response to Dave Post

BTW, I'd love to see your AppleScript for formatting UNIX scripts properly in these forums. I have one that works ordinarily, but it appears that the brackets that can appear in UNIX scripts cause mine to add unwanted strikeouts and font-color changes.

You wrap your code or stuff you do not want the forum to reformat in a pair of
tags

...
... your stuff here
...
{code}
Is there a good book that focuses on Darwin -- especially one that covers scripting fairly thoroughly? I've done a bit of coding in my time, but some of the scripting syntax baffles me.


Here are some Mac OS X Unix oriented books, HOWEVER, I do NOT know how good they are, as I have been playing with Unix since '85. Many books on Unix shell usage (bash) are fairly generic, however, when it comes to administration, things in /etc and things like that, each Unix implementation has its own twist (Mac OS X, Linux, Solaris, AIX, HP-UX, Tru64 UNIX, etc...). In some respects Mac OS X has more admin related differences, as Apple has been trying very hard to handle more of the admin stuff via a GUI than any other Unix implementation.

Anyway here are some pointers. If you can find any of these in a bookstore, you can always browse them before buying.

There is a "Mac OS X for Unix Geeks" book.
<http://www.amazon.com/Mac-OS-Unix-Geeks-Leopard/dp/059652062X/ref=sr 12?ie=UTF8&qid=1299168465&sr=8-2>

There is a "Take Control of Mac Command LIne with Terminal" book
<http://www.takecontrolbooks.com/command-line>

Mac OS X UNIX Toolbox
<http://www.amazon.com/MAC-OS-UNIX-Toolbox-Commands/dp/0470478365/ref=sr 11?ie=UTF8&qid=1299168465&sr=8-1>

A Pratical Guide to UNIX for Mac OS X Users
<http://www.amazon.com/Practical-Guide-UNIX-Mac-Users/dp/0131863339/ref=sr 13?ie=UTF8&qid=1299168465&sr=8-3>

The Mac OS X Command Line: Unix under the Hood
<http://www.amazon.com/Mac-OS-Command-Line-Under/dp/0782143547/ref=sr 14?ie=UTF8&qid=1299168465&sr=8-4>

Mar 3, 2011 8:39 AM in response to Dave Post

BTW, I'd love to see your AppleScript for formatting UNIX scripts properly in these forums. I have one that works ordinarily, but it appears that the brackets that can appear in UNIX scripts cause mine to add unwanted strikeouts and font-color changes.


If you prefer an applescript, here's one that filters what's on the clipboard:
http://putnamhill.net/applescript/esc-forum

It's a little over the top, because I wrote before the I understood the [formatting tags|http://discussions.apple.com/help.jspa#format].

Mar 3, 2011 4:36 PM in response to Frank Caggiano

Frank Caggiano wrote:

How did you search? Remember searching with the Finder ignores hidden files and folders by default.

The problem was that I used both criteria at once, not realizing that Finder apparently ANDs multiple criteria, rather than ORing them. (Don't recall ever using multiple criteria before -- live and learn.) The profile in private/etc is a system file and not hidden.
BobHarris wrote:

Here are some Mac OS X Unix oriented books

<snip>
Anyway here are some pointers. If you can find any of these in a bookstore, you can always browse them before buying.

This looks like an excellent set of starting points. I'll take your advice and see whether I can find them in a bookstore. Thanks again for your help.
Cole Tierney wrote:

If you prefer an applescript, here's one that filters what's on the clipboard:

Works nicely -- thanks!

Mar 3, 2011 5:18 PM in response to Dave Post

Dave Post wrote:
Frank Caggiano wrote:

How did you search? Remember searching with the Finder ignores hidden files and folders by default.

The problem was that I used both criteria at once, not realizing that Finder apparently ANDs multiple criteria, rather than ORing them. (Don't recall ever using multiple criteria before -- live and learn.) The profile in private/etc is a system file and not hidden.


And by default the Finder won't search any directory which doesn't show in the finder window. /etc doesn't show in the finder. Click on your root drive and you'll see this.

Mar 3, 2011 6:07 PM in response to Dave Post

Is there a good book that focuses on Darwin -- especially one that covers scripting fairly thoroughly? I've done a bit of coding in my time, but some of the scripting syntax baffles me.

With respect to shell scripting syntax, books on 'bash' should be useful. While browsing the bookstore, also see if they have copies of:

"Bash Cookbook: Solutions and Examples for Bash Users"

"Learning the bash Shell: Unix Shell Programming"

"Pro Bash Programming: Scripting the Linux Shell"

just ignore the non-Mac OS X stuff 🙂

The other thing that is sometimes helpful is finding useful shell scripts and then taking them apart analyzing each command to understand what it is doing. It really does help if you like what the script does, as that helps to hold your interest.

But more than anything is writing shell script that do useful things for you. Then rewrite it to see if you can make it better using new concepts you find in some book on scripting or by reading 'man bash'. Then rewrite that to make it even better.

One of my most favorite throw away shell script is

ls *.c >tmp.sh

Then edit the newly created tmp.sh file and turn it into a quick script

#!/usr/bin/env bash
while read file
do
do something to the $file variable
done <<EOD
file1.c
file2.c
file3.c
file4.c
etc...
EOD

Sometimes a script like this will be created used and thrown away. But everyonce in a while that "do something to the $file variable" section will be so useful that the script will grow and evolve until I have a several thousand line script that I use everyday to make my job easier.

Mar 3, 2011 9:05 PM in response to Frank Caggiano

Frank Caggiano wrote:

And by default the Finder won't search any directory which doesn't show in the finder window.

Right. My mistake was doing a Find with "System files" set to "include" AND "Hidden files" set to "include", i.e., I used 2 mutually exclusive criteria. Evidently, there are no system files that are hidden, i.e., that have names starting with a period, such as .profile.
BobHarris wrote:

With respect to shell scripting syntax, books on 'bash' should be useful.

This and everything that followed sounds like good advice. Honestly, though, aside from cryptic syntax (which seems endemic in C-like programming languages), I find it hard to follow the flow of control and deeply nested use of functions in the scripts I've seen.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Where are the PATH configuration files?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.