Differences between shell environment variables and set, env, and export

Source: Internet
Author: User
Differences between shell environment variables and set, env, and export 1. classification of shell environment variables and differences between setenvexport: set: Display (set) private variables and user variables included in shell variables, shell of different classes has different private variables bash, ksh, and csh. the differences between shell environment variables and set, env, and export variables are as follows. shell environment variable classification and set env export differences: set: Display (set) shell variables include private variables and user variables. shell of different classes have different private variables bash, each shell private variable in ksh and csh is different. env: Display (set) user variable export: Display (set) the shell variable currently exported as the user variable. For example, [c-sharp] [oracle @ zhou3 ~] $ Aaa = bbb -- shell variable setting [oracle @ zhou3 ~] $ Echo $ aaa bbb [oracle @ zhou3 ~] $ Env | grep aaa -- after setting the current user variable, no [oracle @ zhou3 ~] $ Set | grep aaa -- the shell variable has aaa = bbb [oracle @ zhou3 ~] $ Export | grep aaa -- the export is not exported, and the exported variable is not [oracle @ zhou3 ~] $ Export aaa -- use export to export [oracle @ zhou3 ~] $ Env | grep aaa -- aaa = bbb exists in the user variable. Summary: linux shell variable (set), user variable (env), shell variable contains user variable, export is a command tool that displays the variables that use the export command to import user variables contained in shell variables to user variables. 2. run the unset command to clear environment variables. Note that the [c-sharp] environment variable values set by the set env export can be cleared using the unset command. If no value is specified, the variable value is set to NULL. Example: $ export TEST = "Test... "# Add an environment variable TEST $ env | grep TEST # This command is input to prove that the environment variable TEST already has TEST = Test... $ unset $ TEST # Delete the environment variable TEST $ env | grep TEST # this command has no output, proving that the environment variable TEST does not exist. 3: if the readonly command is used to set the read-only variable [c-sharp], the variable cannot be modified or cleared. Example: $ export TEST = "Test... "# Add an environment variable TEST $ readonly TEST # set the environment variable TEST as read-only $ unset TEST # you will find that this variable cannot be deleted-bash: unset: TEST: cannot unset: readonly variable $ TEST = "New" # this variable cannot be modified.-bash: TEST: readonly variable 4: The most fundamental setting and variable configuration file ~ /. Bash_profile ~ /. Bashrc ~ /. Bash_logout ~ /. The bash_profile user is read when logging on, and the commands contained in them are executed ~ /. Bashrc is read when a new shell is started and executed ~ /. Bash_logout shell is read when you log on and exit. In addition, the initialization process of shell (bash here) is as follows: 1. bash checks whether the file/etc/profile exists. 2. if the file exists, bash reads the file. otherwise, skip 3. bash checks the files in the main directory. whether bash_profile exists. 4. if so, will bash read? File. otherwise, skip Section 5. bash to check whether. bash_login in the main directory exists. 6. if the file exists, bash will read the file. otherwise, skip 7. bash checks the files in the main directory. whether the profile exists 8. if the file exists, bash will read the file. Otherwise, it will be skipped. After these steps are completed, a prompt is displayed. The ksh default prompt is $. 5. the common shell variable PATH contains a series of directories separated by colons, from which the system looks for executable files. If the executable files you enter (such as ls, rc-update, or emerge) are not in these directories, the system will not be able to execute them (unless you enter the full path of this command, such as/bin/ls ). The function of the ROOTPATH variable is the same as that of the PATH variable, but it only lists the directories to be checked when the super user (root) typed the command. The LDPATH variable contains a series of directories separated by colons. the dynamic linker searches for library files in these directories. The MANPATH variable contains a series of directories separated by colons. The Command man searches for man pages in these directories. The INFODIR variable contains a series of directories separated by colons. The info command searches for the info page in these directories. The PAGER variable contains the path of the program browsing the file content (such as less or more ). The EDITOR variable contains the path of the program (file EDITOR) that modifies the file content (such as nano or vi ). The KDEDIRS variable contains a series of directories separated by colons, which contain KDE-related information. The CONFIG_PROTECT variable contains a series of directories separated by spaces, which are protected by Portage during update. The CONFIG_PROTECT_MASK variable contains a series of directories separated by spaces, which are not protected by Portage during update. PATH: determines the directory to which shell will look for commands or programs HOME: current user's main Directory MAIL: refers to the current user's MAIL storage directory. SHELL: The Shell used by the current user. HISTSIZE: the number of historical command records saved. LOGNAME: the logon name of the current user. HOSTNAME: indicates the host name. if a host name is used by many applications, it is usually obtained from this environment variable. LANG/LANGUGE: it is a language-related environment variable. users in multiple languages can modify this environment variable. PS1: a basic prompt. for root users, it is # and for common users, it is $. PS2: A subsidiary prompt. the default value is "> ". You can modify this environment variable to modify the current command line. for example, the following command will change the prompt to the string "Hello, My NewPrompt :)". # PS1 = "Hello, My NewPrompt :)"
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.