For a programmer the linux terminal be like the mic of a speaker, is the tool to communicate with the public, in the same way the shell is the way we communicate with our machine. for this reazon is so important learn how the shell works.
What is a shell for starters?
A shell is a computer program that presents a command line interface which allows you to control your computer using commands entered with a keyboard instead of controlling graphical user interfaces (GUIs) with a mouse/keyboard combination.
For this example we will see what happens when you type ls -l in your linux terminal. LET’S GO…
On the superficial level, typing ls -l displays all the files and directories in the current working directory, along with respective permissions, owners, and created date and time. but how does it work?
1 - BREAK THE COMMAND INTO TOKENS
In this first part the command interpreter break all the line that we wrote in little parts that the shell can interpret.
2 - CHECK FOR ALIASES
The Shell reads the command ls -l from the getline() function’s STDIN, parsing the command line into arguments that it is passing to the program it is executing. The Shell will then check if ls has any aliases associated with the command you entered. If any aliases are found it will expand that alias before running the command and check if the word of the command entered is a built-in command. Next, it will check for special characters such as: “, ‘, \, *, &, # and runs the logic associated with the special character.
3 - CHECK BUILT-INS
Builtin commands are contained within the shell itself. When the name of a builtin command is used as the first word of a simple command
4 - FINDS THE COMMAND IN THE PATH
PATH is an environmental variable in Linux and other Unix-like operating systems that tells the shell which directories to search for executable files
5 - CALL THE PROGRAM LS WITH THE FLAG -l
When the Ls program is find in the $PATH variable se le enviará como argumento el flag -l
6 - PRINT THE PROMPT
The prompt is a short text message at the start of the command line on a command line interface
7 - WAIT FOR A NEW COMMAND TO BE ENTERED
Finally the prompt is displays to enter a new command
And that is what happens when you type ls *.c on your command line. If you have any questions, criticism or comments, feel free to reach out to me via my email here:
I hope this was informative!.