What happens when you type “ls -l” in the shell?

This is not the first version of this question, i asked before and i feel enough enhancement to rewrite it from a different angle and after a beautiful experience working on our own shell in Holberton School project.

Typing commands in the shell is just a simple keystroke on our keyboard and a blink time of waiting and “Voila” we see the result. but the real hard work is under the hood and to walk through this process i step an example of “ls -l” command which expect to show me the list of the present file in the current directory:

Read the line — Keyboard stroke

Lexical analyses

The decision make of the lexical analyzer is based on the available options and resources, the most valuable resource is the ‘environment’ variables especially the “PATH”, which is the main indicator if this command is one of the available program or not. the PATH variable is a list of paths to the possible locations of installed programs in the system. when the shell found the program in this path, consider it as an external program. else is facing two options: either a builtin function or not found based on a predefined list of the built-ins.

In our example “ls -l” the lexical analyzer split the command on two arguments the first is probably the name of the program the second is the passed argument. so after a simple search in the PATH the shell find the suitable location of the “ls” program which is the “/bin” folder. then it’s time to pass all this information to the execution phase.

Execution of the command

So to summarize the walk, we found that the “ls -l” command passing the read phase, then analyzed into understandable tokens by the machine, the the execution phase. with this simple command we skip many phases available in the shell like the expansion and the symbolic feature. May be in the next article :).

Machine Learning enthusiast