<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mukesh</title>
    <description>The latest articles on Forem by Mukesh (@wayward_quark).</description>
    <link>https://forem.com/wayward_quark</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1077010%2F2e2a8409-cb78-4139-88eb-7e8689b5c004.png</url>
      <title>Forem: Mukesh</title>
      <link>https://forem.com/wayward_quark</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/wayward_quark"/>
    <language>en</language>
    <item>
      <title>How Do Shell Commands Function?</title>
      <dc:creator>Mukesh</dc:creator>
      <pubDate>Thu, 20 Jun 2024 12:16:16 +0000</pubDate>
      <link>https://forem.com/wayward_quark/how-do-shell-commands-function-3id2</link>
      <guid>https://forem.com/wayward_quark/how-do-shell-commands-function-3id2</guid>
      <description>&lt;p&gt;&lt;strong&gt;The Role of the Shell: Bridging User Input and Command Execution in Linux&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqgm9muf6u321ic9za77s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqgm9muf6u321ic9za77s.png" alt="Image description" width="800" height="74"&gt;&lt;/a&gt;&lt;br&gt;
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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foi3leuyh79vgga6c2p9m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foi3leuyh79vgga6c2p9m.png" alt="Image description" width="800" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4wvewgrhfwdpz2yk07d6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4wvewgrhfwdpz2yk07d6.png" alt="Image description" width="800" height="138"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37w81r7e2w73xyftmoll.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F37w81r7e2w73xyftmoll.png" alt="Image description" width="800" height="209"&gt;&lt;/a&gt;&lt;br&gt;
Now the shell executes the "&lt;code&gt;cat&lt;/code&gt;" command and creates a child process. The shell process acts as the parent process for the new process created by executing the "&lt;code&gt;cat&lt;/code&gt;" command.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F84kilj41v3bechihdwc2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F84kilj41v3bechihdwc2.png" alt="Image description" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After executing the "&lt;code&gt;cat&lt;/code&gt;" command, the shell returns to the ready state to accept a new command.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>shell</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
