How do I find out where paths in my $PATH were defined?

5

1

There are some paths in $PATH, which I don't want. I'm not sure how they got there; they aren't coming from my .profile. Is there a way to determine which scripts are modifying $PATH?

Peter Hall

Posted 2012-07-16T23:59:41.043

Reputation: 153

Related: Find out where $PATH is defined

– Dennis – 2012-07-17T04:32:30.160

Answers

3

The very first file to processed is /etc/profile. At the beginning of this file, add the line

set -x

then open a new terminal window. You will get more output than you wanted, but it will be a trace of all the bash code that is executed from your startup scripts.

chepner

Posted 2012-07-16T23:59:41.043

Reputation: 5 645

2Nothing happens. What is supposed to happen? – JohnyTex – 2014-09-03T12:32:34.017

4

In OS X, default paths are set in /etc/paths, and possibly in the sub-files (if any) of /etc/paths.d/. See also path_helper(8).

Spiff

Posted 2012-07-16T23:59:41.043

Reputation: 84 656

The accepted answer (about set x) did give me "all the bash code that [was] executed from [my] startup scripts," but it didn't tell me which startup script executed each bit of code. The incorrect behavior I was looking for was caused by a file in /etc/paths.d/. – LiberalArtist – 2016-01-27T18:54:34.190