What is a "sub-process? That is to say, in my current shell situation, open another new shell, and the new shell is a sub-process. In general, the custom variables of the parent process cannot be used within the child process. However, after the variables are changed to environment variables through export, they can be applied under sub-processes.
The child process only inherits the environment variables of the parent process. The child process does not inherit the custom variables of the parent process, therefore, the User-Defined variables in your original Bash will disappear after entering the sub-process, until you leave the sub-process and return to the original parent process.
Why can environment variable data be referenced by the quilt process? This is becauseMemory Configuration.
Theoretically:
- When a shell is started, the operating system allocates a memory block to the shell. The variables in the memory can be used by the sub-process;
- If the export function is used in the parent process, the content of the custom variable can be written to the memory block (environment variable );
- When loading another shell (that is, the promoter process leaves the original parent process), the Child shell can import the memory block of the parent shell's environment variable into its own environment variable block.