Turn from:shell environment variables and set,env,export differences
I. Classification of shell environment variables and the difference between set env export:
Set: Displays (sets) the shell variables, including the private variables and user variables. Different classes of shells have different private variables bash,ksh,csh each shell private variable is not the same.
ENV: Displays (sets) user variable variables.
Export: Displays (sets) The shell variables that are currently exported as user variables.
Export Displays the shell variable currently exported as a user variable and displays the variable's properties (whether read-only), sorted by variable name; Declare, like set, displays the variables defined by the current shell, including the user's environment variables.
Note: The shell variable definition assignment can be set directly in the shell "Name=value", rather than set with set, which is used to display variables and set SH parameters and options.
As an example:
[[email protected] ~]$ aaa=bbb--shell variable settings ~]$ echo $aaa bbb ~]$ env| grep AAA-- Setting the current user variable does not have set | grep AAA- Shell variable has aaa=bbb ~]$ export| grep aaa- This refers to export is not exported, the export variable is not ~]$ Export AAA- - then exporting ~]$ env| grep aaa-- Discover the existence of AAA in user variables
Summary: Linux sub-shell variable (set), user variable (env). Shell variables contain user variables, andexport is a command tool that shows those variables that import user variables contained in shell variables to user variables through the Export command.
Second: Use the unset command to clear the environment variables, note the SET ENV export variable, can be used unset to clear the
Clear the value of the environment variable with the unset command. If no value is specified, the value of the variable is set to NULL. The example below is: $ export Test="test ... " #增加一个环境变量TEST $ env| grep test #此命令有输入 to prove that the environment variable test already exists. Test=Test ... $ unset $TEST #删除环境变量TEST $ env|grep Test #此命令没有输出, proving that the environment variable test no longer exists
Three: Set read-only variables using the readonly command
with the readonly command, the variable cannot be modified or erased. The example is as follows: $ export Test="test ... " #增加一个环境变量TEST ReadOnly test #将环境变量TEST设为只读 $ unset test #会发现此变量不能被删除 readonly variable $ test ="New" #会发现此也变量不能被修改 readonly variable
Four: The most fundamental settings, change the variable configuration file ~/.bash_profile ~/.bashrc ~/.bash_logout
~/.bash_profile is read when the user logs on, and the command contained is executed
~/.BASHRC is read when the new shell is started and executes
~/.bash_logout Shell login is read at exit
In addition, the initialization of the shell (which is referred to as bash) is this:
1.bash Check if file/etc/profile exists
2. If present,Bash is enrolled in the file, otherwise, skip
3.bash check the files in the home directory . Bash_profile is present.
4. If present,bash reads the file, otherwise, skips
5.bash Check if the. Bash_login is present in the home directory.
6. If present,Bash is enrolled in the file, otherwise, skip
7.bash check the files in the home directory . Does the profile exist?
8. if present, Bash is enrolled in the file, otherwise, skip.
When these steps are complete, a prompt appears, ksh the default prompt is $.
V: Common shell variables
path this variable contains a series of directories separated by colons, from which the system looks for executable files. If you enter an executable file (such as LS, rc-update, or emerge) that is not in these directories, the system cannot execute it (unless you enter the full path of the command, such as/bin/ls).
RootPath This variable has the same function as path, but it lists only the directories that the superuser (root) needs to check when typing a command.
Ldpath This variable contains a list of directories separated by colons in which the dynamic linker will look for library files.
MANPATH This variable contains a series of directories separated by colons, which command man to search for man pages in these directories.
Infodir This variable contains a series of directories separated by colons, and command info will search for the info page in these directories.
PAGER This variable contains the path to the program that browses the contents of the file (for example, less or more).
Editor This variable contains the path to the program (file editor) that modifies the contents of the file (such as Nano or VI).
Kdedirs This variable contains a series of directories separated by colons, with KDE-related data. The
Config_protect variable contains a series of directories separated by spaces that are portage protected when they are updated. The
Config_protect_mask variable contains a series of directories separated by spaces that are not protected by portage when they are updated.
PATH: Determines to which directories the shell will look for commands or programs
Home: Current User home Directory
Mail: Refers to the current user's message store directory.
Shell: Refers to what kind of shell is used by the current user.
Histsize: Refers to the number of records in which history commands are saved
LOGNAME: Refers to the login name of the current user.
HOSTNAME: Refers to the name of the host, and many applications are usually obtained from this environment variable if they want to use the host name.
Lang/languge: is a language-related environment variable that users of multiple languages can modify.
PS1: Is the basic prompt, for the root user is #, for the average user is $.
PS2: is a secondary prompt, the default is ">". You can modify the current command by modifying this environment variable, such as the following command to modify the prompt to a string "hello,my newprompt:) ”。
# ps1= "Hello,my newprompt:) "
Disclaimer: This document can be changed at will, but must be signed by the original author
Phoenix Dancer qq:578989855
Shell variables/environment variables and set/env/export usage _ go