Let's say I installed Python. I got the python command in the terminal. But how did this happen? The python setup file created a new executable file in the bin directory? If so, how? And generally, how do developers of interpreters and platforms like Node.js and Cordova add new commands to the command shell (terminal)? Is bash used?

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

The PATH variable contains a list of directories in which the operating system tries to search for executable files if the user did not explicitly specify the path to the desired executable file at startup.

Let's imagine that there are two different versions of the Python programming language interpreter installed on a Windows computer. This can be done if you install them in different directories, for example, C: \ Python27 and C: \ Python34 . The executable file for both versions is called python.exe .

In order to run the executable file of the desired version, you can specify the full path to it, for example, C: \ Python34 \ python.exe:

enter image description here

But every time the full path to indicate laziness, and yes even remember it should be.

The alternative is to add the path to the directory where this executable file is located in the PATH environment variable, and then it can be run, indicating only the name. And to find out where it is (according to the operating system), you can use the where command in the Windows operating system or the which command in the Linux or MacOS operating system.

enter image description here

In more detail, in the original article.

  • one
    Add: in addition to the PATH there is also the registry HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths , where you can specify the display of specific names on specific paths (plus the PATH modification for this program). And it seems to me that these names do not have to match the actual file names. - окт
  • Did not know about which in Linux, always used whereis - Beast Winterwolf

Terminal Commands are really just executable files in the tables of contents that are listed in your PATH environment variable.

Of course, there are also commands built into bash (or another command line interpreter), for example, umask (this is necessary because it changes the state of the interpreter itself) or echo (for efficiency).

The python command that you mention is located in the /usr/local/bin table of contents, by the way, you can always figure it out by typing

 avp@avp-ubu1:~$ which python /usr/bin/python 

and represents

 avp@avp-ubu1:~$ file /usr/bin/python /usr/bin/python: symbolic link to python2.7 avp@avp-ubu1:~$ ll /usr/bin/python lrwxrwxrwx 1 root root 9 Dec 10 2015 /usr/bin/python -> python2.7* avp@avp-ubu1:~$ 

in the end

 avp@avp-ubu1:~$ ll /usr/bin/python2.7 -rwxr-xr-x 1 root root 3546104 Jul 2 22:05 /usr/bin/python2.7* avp@avp-ubu1:~$ file /usr/bin/python2.7 /usr/bin/python2.7: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=dadc6dc447374ae242ac392c67c898e3d5f49972, stripped avp@avp-ubu1:~$ 

binary executable (i.e. directly executable CPU) file.

It was created there by the apt-get installer (or yum , depending on the version of Linux), by executing the installation procedure commands that are included in the package (.deb file (or .rpm)) containing python.

What specific command directly in the installation procedure created the file /usr/bin/python2.7 can be said only by opening the package and looking at the text of the installation script. We can assume that cpio (or even just cp, or tar), but this is not important, because in fact, just one of the package files was copied to the desired table of contents, and then the necessary privileges were set to it.

About the question of whether bash is used in this process, in general one can say the same thing (imho most likely yes, it is used) - one should look at the contents of the package.