Post Address: http://keep88.blog.51cto.com
Bo main name: Li Changming
This note is from------and the old boy learn Linux OPS "shell programming Combat"
Directory:
Core basic knowledge and practice of shell variables
1. Variable type:
Environment variables (global variables) and normal variables (local variables)
2. Custom Environment variables:
1), set the environment variables (global variables) of several methods:
Cases:
(1), export variable name = "Value" (2), Variable name = "value", Export variable name (3), declare-x variable name = "Value"
These are three ways to set global variables, and if you want to continue to take effect after restarting, set any one of the global variables into the Global environment variable configuration file.
1), the Global environment variable configuration file is as follows:
/etc/profile/etc/bashrc/etc/profile.d
2), the user's environment variable configuration:
/user/.bashrc/user/.bash_profile
3, set the login prompt two ways:
1), [[email protected] ~]# CAT/ETC/MOTD Welcome to LCM Linux Shell training
After logging in, the following content appears:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/97/3F/wKioL1krmUSRf7xoAAAEFiQ9h34682.png "title=" 2017-05-29_114420.png "alt=" Wkiol1krmusrf7xoaaaefiq9h34682.png "/>
2), [[email protected] ~]# cat/etc/profile.d/lcm.sh echo "Here is LCM training ..." #<== Script Content
4. Use unset to cancel local variables and environment variables:
[Email protected] ~]# export name= ' lichangming ' [[email protected] ~]# echo $namelichangming [[email protected] ~]# unset Name[[email protected] ~]# echo $name #<== The variable name was canceled
5. Basic techniques and summary of variable definition:
Note the difference between ' single quote and double quote '
Example:
ip=192.168.1.2a=192.168.1.2-$IPb = ' 192.168.1.2-$IP ' c= "192.168.1.2-$IP" echo "a= $a" echo "b= $b" echo "C=${c}" the results are as follows: A= 192.168.1.2-192.168.1.2b=192.168.1.2-$IPc =192.168.1.2-192.168.1.2
From the above results analysis:
1), $ variable name represents the output variable, can be used in either $ A or ${a} two usages
Variables defined using the ' single quotation mark ' will output the original text. A variable in single quotation marks is not referenced, it is treated as a string output
Variables defined using the double quotation mark, if a variable is referenced, the variable is parsed and output.
Summarize:
The variable definition of the digital content can be without quotation marks, other non-specific strings such as the definition of the best combination of double quotation marks, if you really need to add a single quotation mark, the definition of variable double quotation marks is the most common usage scenario
6, using the function output time: (os:centos6.5)
echo $ (date +%f)
650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/97/4C/wKiom1ktCv_zZAfvAAASk65f2wU767.png "title=" 2017-05-30_135709.png "alt=" Wkiom1ktcv_zzafvaaask65f2wu767.png "/>
Note:
This on-output time notation is typically used to identify the file name in the persistent backup.
Summarize:
(1), variable name and variable content definition summary: Variable names can only be letters, numbers or underscores, only the letter or underscore the definition of the variable name to be standardized, with intent. (2), several methods of calling variables: $ variable name ${variable name}$ (variable name)
This article is from the "Keep Keep your" blog, be sure to keep this source http://keep88.blog.51cto.com/11829099/1930688
Shell Programming (i)