Back to lessons

Apple Terminal

Show Your PATH One Entry Per Line

A tool runs from an unexpected location because PATH order is unclear.

Command

echo "$PATH" | tr ':' '\n' | nl -ba

What changed

Nothing changes. The command formats PATH for easier reading.

Danger

safe

When to use it

Use when Homebrew, npm, pyenv, rbenv, or Xcode command line tools seem to resolve the wrong executable.

When not to use it

Do not use it as proof that a command exists. Pair it with command -v for that.

Undo or recovery

No undo needed because this command is read-only.

Expected output

A numbered list of PATH directories in search order.

demo script

Disposable terminal steps

  1. PATH_FIXTURE='/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin'; echo "$PATH_FIXTURE"
  2. PATH_FIXTURE='/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin'; echo "$PATH_FIXTURE" | tr ':' '\n' | nl -ba

simulated output

What it looks like

disposable vessel
::fixture-ready::
$ PATH_FIXTURE='/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin'; echo "$PATH_FIXTURE"
/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin
::exit-code::0
$ PATH_FIXTURE='/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin'; echo "$PATH_FIXTURE" | tr ':' '\n' | nl -ba
     1	/opt/homebrew/bin
     2	/usr/local/bin
     3	/usr/bin
     4	/bin
::exit-code::0

YouTube Short

Read PATH clearly.

PATH bugs are often order bugs. Split the variable on colons, number the lines, and see where your Mac looks first.

LinkedIn hook

Wrong Node, Python, or FFmpeg? Start by reading your PATH clearly.

Question: How often do your toolchain bugs turn out to be PATH order problems?

experiments

A/B tests to run

Metric: save_rate

A: Mention Node and Python in the hook.

B: Mention Homebrew and Xcode in the hook.