Introduction
3000 block of wages and 30000 wages, the gap lies in the latter has the accumulation of life experience, the summary of technical knowledge is also a life experience.
1) What is a shell variable?
A variable is a simple character to replace a complex character.
2) How many shell variables are there?
Environment variables and local variables
3) How are variables defined and referenced?
Variable name = variable Content # content can be path, command, string, number, etc.
Variable reference $ variable name # such as Cheng=30
# echo $cheng #结果就是30
4) Special variables (the system has pre-defined characters that represent fixed content)
The name of the shell script
$n the nth parameter of a shell script
$* [email protected] All the parameters of the shell script (slightly different from the data analysis can be checked)
$# the number of arguments to the shell script
Special variables that are not commonly used
$! The process number of the last script running in the background
$$ the process number of the script
$? The return value of the previous command or script in the shell script (what is the return value? can be used as a non-existent, only when the wrong time)
$_ the last parameter of the script
5) The substring of the variable (sometimes we need to get a part of the variable, at which time the variable quantum string is the fastest way to calculate)
Such as
Cheng=ruofei
echo ${#cheng} #计算变量的字符个数
6
Echo ${cheng:2} #显示第2个字符以后的字符
Eng
6) Calculation of variables
When the content of a variable is a number, it involves the numerical calculation of the variable, which we use (()) to automatically calculate
Such as
Cheng=30
Zhang=cheng+1
Echo $zhang
Cheng+1
Zhang= ((cheng+1))
Echo $zhang
31
Linux self-Study _shell variable Chapter