1. Variables
A variable is a variable whose value is allowed to change during program operation; a variable is a method of using a string of fixed characters to indicate an unfixed value; a variable is a convenient placeholder for referring to a computer Memory address, this address can store program information that can be changed when Script is running . Variables in the shell cannot be permanently stored in the system and must be declared in the file
1. Types of variables in shell scripts
Variables in the shell are divided into
(1) Environment-level variables: Environment-level variables only take effect in the current shell, and shell shutdown variables are lost
(2) User-level variables: User-level variables are written in the user's bone file and only take effect for the current user
vim ~/bash_profile ##Current user's home directory user variable profile
export westos=1
Obviously switching to the student user, the variable westos does not take effect
(3) System-level variables: System-level variables are written in the system configuration file /etc/profile or /etc/profile.d/, and are valid for all users
vim /etc/profile ##System variable configuration file
Of course, the environment path of the script also follows this principle, and there are also user environment paths and system environment paths.
User environment path:
System environment path:
source /etc/profile ##Add variables to the configuration file
2. Variable value transfer
$1 The first string after the script
$2 the second string after the script
$3 The third string after the script
$# The number of characters in the string following the script
$* all strings followed by the script, the pattern is " 1 2 3 "
&@ All strings followed by the script with the pattern "1" "2" "3"
3. Character translation
${} variable declaration
\ translates a single character
"" Weak reference, batch translation"" Characters appearing in
'' strong reference, batch translation of characters appearing in ''
The difference between '' and "" is that "" cannot translate "\","`","!","$"
4. Alias settings in the system
alias ##List aliases in the system
alias write='vim' ##vim's alias is write, both have the same effect
vim .bashrc ##Configuration file for alias settings
unalias write ##Unalias
2. Operation
1. Operation methods and operation symbols
2. Common operation commands in shell
bc ## calculator in linux
scale=n ##Keep the number of decimal places