Instructions have paths, too
What’s the one terminal command you utilize probably the most? Definitely, mine is git
as I regularly make commits whereas writing articles.
The rationale I’m asking is as a result of most terminal instructions have their very own paths within the working system as effectively. To search out that path, you solely must run which valid_command_name
. For instance, right here is the trail to my git
occasion:
$ which git # In home windows, use `the place`/usr/bin/git
You would possibly acknowledge that the above is an absolute path. However it’s a path to what, precisely?
An executable binary file! (In case you are in Home windows, you’re going to get a .exe
file path)
It incorporates directions on what to do when git
instructions are run. All terminal instructions are shell scripts or executables in some kind that carry out sure duties.
For instance, you may strive the which
command on built-in terminal instructions like clear
, cat
or contact
and you’ll get absolute paths (for even the which
command itself).
When you get the trail to the executable, you may strive operating a command with its full path like this:
$ /usr/bin/git standing -s # the identical as `git standing -s`M 2023/6_june/7_path/dump.ipynb
And it really works! However here’s what’s attention-grabbing — how can the phrase git
is equal to absolutely the path /usr/bin/git
? I imply, git
is only a phrase.
How does your laptop know the complete executable paths of so many instructions and may run them with solely a single key phrase?
(That is the eureka second!)
Utilizing the PATH variable!