Shell's Export command

Source: Internet
Author: User

Export Feature Description: Sets or displays environment variables.
syntax:export [-fnp][variable name]=[variable setting value]
Additional Note: when executing a program in the shell, the shell provides a set of environment variables. Export can add, modify, or delete environment variables for use by subsequent executing programs. The effect of export is limited to that landing operation.
Parameters
-F represents the function name in [variable name].
-n Deletes the specified variable. The variables are not actually deleted, but are not exported to the execution environment of the subsequent directives.
-p lists all the environment variables that the shell assigns to the program.

After the user logs on to the Linux system, a user shell is launched. In this shell, you can use the shell command

or declare a variable, you can also create and run a shell script program. When you run a shell script, the system creates a child shell.

At this point, there will be two shells in the system, one for the system-initiated shell at login, and the other for the system to run the script program.

's Shell. When a script is finished running, the script shell terminates and returns to the shell before executing the script.

In this sense, a user can have many shells, each of which is derived from a shell, called the parent shell.

A variable defined in a child shell is valid only within that child shell. If a variable is defined in a shell script program,

When the script is run, the defined variable is only a local variable within the script, and the other shell cannot reference it.

To enable the value of a variable to be changed in another shell, you can use the Export command to output a defined variable.

The export command will allow the system to define a copy of the variable when it creates each new shell.

This process is called variable output.

Conclusion:

1, the script is executed in a child shell environment run, the script after the execution of the child shell automatically exit;

2. A system environment variable in a shell is copied into a child shell (a variable defined with export);

3. A system environment variable in a shell is valid only for the shell or its child shell, and the variable disappears at the end of the shell
(and cannot be returned to the parent shell).

3. Variables defined without export are valid only for the shell, and the child shell is not valid.

Why does a script execute directly and execute a line with source? This is the original manual:

Read and execute commands from filename in the current shell environment and
Return the exit status of the last command executed from filename.

Executing a script file directly is run in a child shell, while source is running in the current shell environment.

Export command for Shell

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.