Page 132 - DCAP106_OPERATING_SYSTEM_TOOLS
P. 132

Unit 7: The Shell




          7.3 Built-in Programs and External Programs                                           Notes

          All the Linux commands can be classified into two types:

          z z  Internal commands
          z z  External commands
          The commands which are directly executed by the shell are known as internal commands. These
          are built-ins in the shell. Internal commands do not depend on paths as they are not coded in
          files. Dissimilar to external commands, when an internal command is executed, no process is
          created. Commands like pwd, cd ,echo comes under the category of the  internal commands.

          The  files present in the $PATH are considered as external commands.  This is to note that, in
          Linux, everything is represented in the form of files. The files do not get executed if they are not
          present in the path specified by the $PATH variable. Likewise, if the files are available but are
          not present int the path specified by $PATH, the commands cannot be executed. Another point
          worth noting is that every time an external command gets executed, a new process gets spawned.
          Commands like ls,cp etc. comes in this category.
          Now let us differentiate between internal and external commands.
          There is a Linux command ‘type’, which determines how its arguments would be interpreted if
          they were utilised as a command name. We can use this  command to identify among the two
          types of commands. Execute the command : type <command>
          In the case when the output states that the command is shell built-in, it is an internal command.
          Or else, if the output states that the command is present in /bin, then it is an external command.

                 Example: cd and pwd are examples of internal commands.

          1.  savita@Amrita:~$ type cd
          2.  cd is a shell builtin
          3.  savita@Amrita:~$ type pwd
          4.  pwd is a shell builtin
          5.  savita@Amrita:~$
          cp and mv are examples of external commands.

          1.  savita@Amrita:~$ type cp
          2.  cp is /bin/cp
          3.  savita@Amrita:~$ type mv
          4.  mv is /bin/mv
          5.  savita@Amrita:~$
          Nevertheless, there might be certain commands having files in /bin directory and simultaneously,
          are also built-ins in the shell. Then, the first preference would always be given to the internal
          command. It means that even if the corresponding file did not exist, it would be executed by the
          shell as a built-in.

                 Example: Linux command echo.
          Table 7.2 shows some of the differences between internal and external commands:









                                           LOVELY PROFESSIONAL UNIVERSITY                                   125
   127   128   129   130   131   132   133   134   135   136   137