How are built-in commands implemented in the shell?

When a shell (such as bash ) calls an executable file, first it is fork , and then a copy of it execve executable file.

When the shell invokes built-in commands, a new process is not created, and execve can only work with executable files, and built-in commands are not stored in executable files.

So, how are built-in commands stored and how are they called in terms of system calls?

+5
source share
3 answers

"built-in command" means that you do not need to run an external program. So no, there is no execve at all, and no, there is not even any system call involved. Your shell really just parses the command line and sees "hey, what a built-in command, let it perform this and this function."

+1
source

You can imagine that they are the same as the shell functions.

Thus, instead of starting an external process, the shell calls some internal function of the function functions, which reads the input data, outputs the result, and does almost the same as the main function of a regular program.

+1
source

The shell process itself processes the embedded file and possibly modifies it or the environment. Perhaps there were no system calls.

0
source

Source: https://habr.com/ru/post/1247218/


All Articles