In linux, shell script execution methods and exec and source commands exec and source both belong to bash Internal commands (builtins commands ), enter man exec or man source in bash to view information about all internal commands. Www.2cto.com bash shell commands are divided into two types: External commands and Internal commands. External commands are implemented through system calls or independent programs, such as sed and awk. Internal commands are implemented by special file formats (. def), such as cd, history, and exec. Before explaining the differences between exe and source, describe the concept of fork. Fork is a linux System Call used to create child processes ). A child process is a copy of the parent process. It obtains a certain amount of resource allocation from the parent process and inherits the environment of the parent process. The unique difference between a child process and a parent process lies in the pid (process id ). The environment variable www.2cto.com (the variable passed to the sub-process is essentially different from the local variable and the environment variable) can only be transmitted from the parent process to the sub-process in one way. How the environment variables of a non-process change will not affect the environment variables of the parent process. Shell script: There are two methods to execute shell scripts. One is to generate a new shell and then execute the corresponding shell scripts. The other is to execute the script under the current shell and no other shells are enabled. To generate a new shell and then execute scripts, add the following statement at the beginning of the scripts file #! The common script file (. sh) of/bin/sh is this usage. In this way, the new sub-shell (new sub-process) is started, and then the command is executed under it. Another method is the source command mentioned above. instead of creating a new shell, execute all the commands in the current shell. Source: The source command is the dot (.) command. Enter man source in bash and find the explanation of the source command. You can see the explanation "Read and execute commands from filename in the current shell environment and ...". It can be seen that the source command is to execute the commands in the parameter file in the current process, rather than starting another sub-process (or sub-shell ). Exec: enter man exec in bash and find the exec command description. "No new process is created. this means that the exec command does not generate a new sub-process. So what is the difference between exec and source? When the exec command is executed, the current shell process is closed, and the subsequent command is switched to continue execution.