How Do Shell Commands Function?

The Role of the Shell: Bridging User Input and Command Execution in Linux

Shell is a program that takes user inputs and passes them to the operating system. It provides an interface to accept commands and their arguments, invokes system calls, and run…


This content originally appeared on DEV Community and was authored by Mukesh

The Role of the Shell: Bridging User Input and Command Execution in Linux

Shell is a program that takes user inputs and passes them to the operating system. It provides an interface to accept commands and their arguments, invokes system calls, and runs other programs.

A Terminal program, such as iTerm2, is a GUI that interacts with the shell, such as Z shell. It accepts text commands and displays the output.

Image description
The above screenshot is from a terminal with a shell process in ready state, waiting for a user to enter a command through the keyboard.

Image description

Once the user types above command and hits the enter key, the shell searches a file named "cat" through a list of directories stored in $PATH environment variable, separated by ":" .

Image description

In our case, the file "cat" is stored in the directory "/usr/bin". The contents of the "/usr/bin" directory, as shown in the screenshot below, include the "cat" file. In Linux, we have files and processes. When "cat" is executed, a process is created with a unique number called a PID. This PID is used by system calls and other processes.

Image description
Now the shell executes the "cat" command and creates a child process. The shell process acts as the parent process for the new process created by executing the "cat" command.

Image description

After executing the "cat" command, the shell returns to the ready state to accept a new command.


This content originally appeared on DEV Community and was authored by Mukesh


Print Share Comment Cite Upload Translate Updates
APA

Mukesh | Sciencx (2024-06-20T12:16:16+00:00) How Do Shell Commands Function?. Retrieved from https://www.scien.cx/2024/06/20/how-do-shell-commands-function/

MLA
" » How Do Shell Commands Function?." Mukesh | Sciencx - Thursday June 20, 2024, https://www.scien.cx/2024/06/20/how-do-shell-commands-function/
HARVARD
Mukesh | Sciencx Thursday June 20, 2024 » How Do Shell Commands Function?., viewed ,<https://www.scien.cx/2024/06/20/how-do-shell-commands-function/>
VANCOUVER
Mukesh | Sciencx - » How Do Shell Commands Function?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/06/20/how-do-shell-commands-function/
CHICAGO
" » How Do Shell Commands Function?." Mukesh | Sciencx - Accessed . https://www.scien.cx/2024/06/20/how-do-shell-commands-function/
IEEE
" » How Do Shell Commands Function?." Mukesh | Sciencx [Online]. Available: https://www.scien.cx/2024/06/20/how-do-shell-commands-function/. [Accessed: ]
rf:citation
» How Do Shell Commands Function? | Mukesh | Sciencx | https://www.scien.cx/2024/06/20/how-do-shell-commands-function/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.