Programs are a regular executable file written in any language (mainly C).
The shell accepts an input command that is just a string. He then looks for specific sequences of characters that have particular meaning for the shell, such as environment variables that are $ , followed by a word or redirects that are > , followed by a path. After this substitution has been preformed, it has a line that is split into spaces to generate the name of the executable file and parameters. The shell will then search for the executable in the directory list in the PATH environment variable. The shell then uses system calls to create a process from an executable file with parameters.
For example, to execute the ls $HOME , the shell first recognizes that $HOME is an environment variable and substitutes its value in this case /home/user , leaving the ls /home/user . He then splits the command into space to get the ls executable and the /home/user option. The shell finds the first executable that matches ls usually /bin/ls . He then uses the on-air calls to spawn () / posix_spawn () or fork () and exec () to create a new process.
user1937198
source share