Environmental Path Variables (Terminal)

Here’s a question about the Mac user command line environment.

I’m not as good as I should be with the command line, but I have a question that I’m sure some, if not many, TidBITS talk readers might help with.

First, I’ll start with a tip. If you ever use your Terminal app, you are probably aware of the path that tells your Terminal (and other stuff) what commands to use, so you don’t have to type in the full path of the command (example: if you have a Silicon Mac, and have installed Homebrew to manage command line programs on your Mac, you’ll probably know that by default, Homebrew puts many commands in the folder “/opt/homebrew/bin/”. Homebrew typically adds that folder designation to your path environmental variable so you can use programs by typing the name without prepending “”/opt/homebrew/bin/" to the command line. For me, and for many users of the zsh shell environment that is default for Ventura, that specification exists in an invisible file in my home folder called “.zshrc”.) I may not have explained that well or even extremely accurately.

Anyway here’s the tip. The following is a command line function you can add to your zshrc (or basic) or other file where your system’s environment is configured) that will allow you to enter the command cpath in a Terminal window to see a one-per-line listing of your path items:

function cpath {
    echo "$PATH" | tr ':' '\n' | sort | uniq -c

You can replace cpath with seepath or something else.

My question is this. I don’t view the path as often as I should, now I’m seeing some entries that don’t seem as though they should be there. Can anyone tell me where those included at the end of this post came from, or offer advice about how I can find out where they came from? As a rule, Apple doesn’t include any changes in software updates or installations that affect the user’s command line environment. Here are the unfamiliar path entries viewed using the cpath command explained above (one per line). Thanks.


I wouldn’t use uniq – it’s better to find out if you have duplicates in the $PATH.

1 Like

Yes, of course, but doesn’t that number at the start of each line count the occurrences for you? (I was assuming it did.) (I’m referring to the number at the beginning of each line in the cpath output when the function is active.)

Well, it was Ventura installation, after all. I haven’t seen users’ environment settings changed by Apple in a long time, that I remember. Of course it’s not the first time the default environment itself has been changed, Apple has done that a lot. Maybe they’ve changed more that I’ve been aware of, and I didn’t notice because the new entries weren’t so conspicuous. Anyway, the paths are added in two files: /private/etc/paths.d/10-cryptex and /private/etc/paths. The first file (adding three of the four paths) was mentioned here, and that gave me enough of a clue to quickly find the second one.

In other words, never mind.


More info about cryptexes:

1 Like

Ah. Quite right.

I overlooked the -c switch…

In that case I think I’d sort the output again, so the digits sort together, but YMMV.

echo $PATH | tr ':' '\n' | sort | uniq -c | sort -h

Hmm, output appears identical OMM.


1 Like