The PATH Variable For the Confused Data Scientist: How to Manage It | by Bex T. | Jun, 2023


Commands have paths, too

What is the one terminal command you use the most? Without a doubt, mine is git as I frequently make commits while writing articles.

The reason I am asking is because most terminal commands have their own paths in the operating system as well. To find that path, you only have to run which valid_command_name. For example, here is the path to my git instance:

$ which git  # In windows, use `where`

/usr/bin/git

You might recognize that the above is an absolute path. But it is a path to what, exactly?

An executable binary file! (If you are in Windows, you will get a .exe file path)

It contains instructions on what to do when git commands are run. All terminal commands are shell scripts or executables in some form that perform certain tasks.

For example, you can try the which command on built-in terminal commands like clear, cat or touch and you would get absolute paths (for even the which command itself).

Once you get the path to the executable, you can try running a command with its full path like this:

$ /usr/bin/git status -s  # the same as `git status -s`

M 2023/6_june/7_path/dump.ipynb

And it works! But here is what’s interesting — how can the word git is equivalent to the absolute path /usr/bin/git? I mean, git is just a word.

How does your computer know the full executable paths of so many commands and can run them with only a single keyword?

(This is the eureka moment!)

Using the PATH variable!



Source link

Leave a Comment