Linux under Export command Add, DELETE environment variable (reprint)

Source: Internet
Author: User

transferred from: http://blog.csdn.net/shenshendeai/article/details/49794699 Export Command

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 only extends to the operation of this landing.

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.

When a variable is created, it is not automatically known to the shell process that was created after it. The command export can pass the value of the variable to the following shell. When a shell script is called and executed, it does not automatically get access to the variables defined in the original script (caller) unless the variables have been explicitly set to available.

The export command can be used to pass the value of one or more variables to any subsequent script.

three implementation methods for setting environment variables in Linux (export PATH): 1. Direct use of the Export command (we illustrate with MySQL service)

[Email protected] ~]# export path= $PATH:/usr/local/mysql/bin

Check to see if it's set up, you can use the command Export command to view it, or you can view it directly by #变量名 #

zhongweichaomatomacbook-pro:~ zhongweichao$ $PATH

-bash::/users/zhongweichao/.local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/x11/bin:/users/ Zhongweichao/develop/jboss-5.1.0.ga/bin

Note: Variables set directly with export are temporary variables , meaning that the value defined for the variable will not take effect if you exit the current shell. How can we make the variable that we define take effect permanently? That depends on the way we define the second.

2. Modify/etc/profile

[Email protected] ~]# Vi/etc/profile

Export path= $PATH:/usr/local/mysql/bin # Add this line configuration in the configuration file

It is important to note that after modifying this file, you must use the following command to make the modified content effective without rebooting the system.

[Email protected] ~]# Source/etc/profile

Or the use of '. ' :

[Email protected] ~]#. /etc/profile

View:

[Email protected] ~]# echo $PATH

/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/ Usr/local/mysql/bin

# Configuration is in effect

3. Modify the. bashrc file to take effect under the current user shell

# VI/ROOT/.BASHRC? Add in:

Export path= $PATH:/usr/local/mysql/bin

After modifying this file, you also need to use source or. Make the configuration file effective.

Then use the Echo $PATH to see if the variable takes effect

[Email protected] ~]# echo $PATH

/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/ Usr/local/mysql/bin

shell and Export commands

After the user logs on to the Linux system, a user shell is launched. In this shell, you can use a shell command or declare a variable, or you can 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 logon, and the other for the shell created by the system to run the script. When a script is finished running, its script shell terminates and can be returned to the shell before the script executes. 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, when the script is run, the defined variable is only a local variable within the script, and the other shell cannot reference it, so that the value of one variable can be changed in the other shell. You can use the Export command to output a defined variable. The export command will allow the system to define a copy of this variable when creating each new shell. This process is called variable output.

(http://blog.csdn.net/bailyzheng/article/details/7488769)

Linux under Export command Add, DELETE environment variable (reprint)

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.