T
T
tef2015-12-25 06:40:37
Command line
tef, 2015-12-25 06:40:37

What algorithm does the console have when you write the name of the application and the command in it?

I'm not sure yet if I'm asking the right question, but I'd like to see understanding begin to take shape.
Let's say I write git, and then I write commit next. For starters, I'm wondering what happens when I write git(application name)? How does the console know that I have git installed and that when I write git, I need to run a command with it? And a follow-up question: how does the console know about git commands and what to do with them?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2015-12-25
@tef

The console knows nothing. In the simplest case (if one command is typed without pipes and stream redirection):
When you type a line and press Enter, first the first substring is separated from the line up to a space (or the end of the line if there are no spaces). The remainder of the string will be passed to the executed command as arguments.
It then checks to see if this substring is an internal shell command. If yes, then this command is executed.
If this is not an internal command and the full path to the file is not specified, then a file with that name is searched for in the directories listed in the PATH environment line. If the file is found and the user has rights to run it, then it is run.
If the full path is specified (for example, /usr/bin/perl), then the search is not performed, only a check for launch rights is performed.
PS. If we are talking about dos / windows cmd, then it looks for files by adding the extensions .bat, .cmd, .exe, if the extension is not specified explicitly. In addition, it starts searching from the current directory, and then through the PATH variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question