Variable
Echo $PATH
Echo $HOME
Echo $PWD
Echo $LOGNAME
System Preset variables are
#env can show which variables are in the system preset in the current directory.
#set can display not only system-preset variables, but also user-defined variables.
You can define your own variables. However, variables can only take effect in the current shell.
This variable can be used by all users in the system to log in
Add Export myname = aming at the end of the/etc/profile file and then run Source/etc/profile to take effect. You can see the effect by running the Bash command at this time or directly su-test the account.
[Email protected] ~]# echo "Export myname=aming" >>/etc/profile
[Email protected] ~]# source!$
Source/etc/profile
[Email protected] ~]# bash
[Email protected] ~]# echo $myname
Aming
[[Email protected] ~]# exit
Exit
[Email protected] ~]# su-test
[Email protected] ~]$ echo $myname
Aming
Note that a single quotation mark is required when the variable contents have a special symbol;
[Email protected] ~]# myname= ' aming Li '
[Email protected] ~]# echo $myname
Aming Li
In another case, a single quotation mark in a variable requires double quotation marks.
[Email protected] ~]# myname= "aming ' s"
[Email protected] ~]# echo $myname
Aming ' s
Variable content requires other commands to run the result can be used in reverse quotation marks;
[Email protected] ~]# myname= ' pwd '
[Email protected] ~]# echo $myname
/root
Variable content can accumulate the contents of other variables, need double quotation marks;
[Email protected] ~]# myname= "$LOGNAME" aming
[Email protected] ~]# echo $myname
Rootaming
Perhaps you can see from the above examples that the difference between single and double quotation marks does not cancel the function of the special characters that appear inside ($), and the special characters in single quotation marks all lose its function.
In the previous example, Amin has used the Bash command multiple times, and if you run the bash instruction in the current shell, it will enter a new shell, which is the Shell's child shell, so you might want to use the Pstree command to see it.
[Email protected] ~]# pstree |grep Bash
|-login---Bash
|-SSHD---sshd---bash-+-grep
[Email protected] ~]# bash
[Email protected] ~]# pstree |grep Bash
|-login---Bash
|-SSHD---sshd---bash---bash-+-grep
Pstree This command will print all the processes in the Linux system through a tree structure. Limited to space Amin not all listed, you can directly enter the Pstree view. After a variable is set in the parent shell, the variable is not
will take effect if you want this variable to take effect in the child shell, use the export directive.
[Email protected] ~]# abc=123
[Email protected] ~]# echo $ABC
123
[Email protected] ~]# bash
[Email protected] ~]# echo $ABC
[[Email protected] ~]# exit
Exit
[Email protected] ~]# export ABC
[Email protected] ~]# echo $ABC
123
[Email protected] ~]# bash
[Email protected] ~]# echo $ABC
123
Export is actually a declaration of the meaning of this variable, so that the shell's child shell also know that the value of the variable ABC is 123. If no variable name is added to the export, it declares all variables.
[Email protected] ~]# export
Declare-x g_broken_filenames= "1"
Declare-x histcontrol= "Ignoredups"
Declare-x histsize= "1000"
Declare-x home= "/root"
Declare-x hostname= "Localhost.localdomain"
Declare-x lang= "ZH_CN. UTF-8 "
Declare-x lessopen= "|/usr/bin/lesspipe.sh%s"
Declare-x logname= "Root"
Declare-x
Ls_colors= "rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;0 5;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=3
7;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31 :*. zip=01;31:*.z=01;31:*. z=01;31:*.dz=01;31:*.gz=01;31:*.
Lz=01;31:*.xz=01;31:*.bz2=01;31:*.tbz=01;31:*.tbz2=01;31:*.bz=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar= 01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7
Z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga= 01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.
png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*. Mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;3
5:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:* . fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:
*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*. Au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;3
6:*.MP3=01;36:*.MPC=01;36:*.OGG=01;36:*.RA=01;36:*.WAV=01;36:*.AXA=01;36:*.OGA=01;36:*.SPX=01;36:*.XSPF=01;36: "
Declare-x mail= "/var/spool/mail/root"
Declare-x oldpwd
Declare-x path= "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
Declare-x pwd= "/root"
Declare-x shell= "/bin/bash"
Declare-x shlvl= "3"
Declare-x ssh_client= "10.72.137.107 50947 22"
Declare-x ssh_connection= "10.72.137.107 50947 10.72.137.159 22"
Declare-x ssh_tty= "/dev/pts/0"
Declare-x term= "Xterm"
Declare-x user= "Root"
Declare-x abc= "123"
Declare-x myname= "\ $LOGNAMEAming"
The last side, along with our custom variables, are declared.
How do I set a variable in front of you, and what if I want to cancel a variable? Just enter the unset variable name.
[Email protected] ~]# echo $ABC
123
[Email protected] ~]# unset ABC
[Email protected] ~]# echo $ABC
Subtotal: Variables The first system has its own variables. $PATH HOME LOGNAME PWD. Besides this, there's env. Shows all variables in the current account set display all variables. Bash custom variables can only be implemented in the current account, if you want all accounts to be
The implementation needs to be added to the "/etc/profile" file at the bottom of the export Myname=wangshuai and then run the source!$ run bash directly with another account test. Just want to execute in the current directory
This article is from the "Aming-linux Learning" blog, so be sure to keep this source http://937174156.blog.51cto.com/8141519/1735599
Linux Partial variables