First, declaring variables
Myurl= "http://see.xidian.edu.cn/cpp/linux/"
mynum=100
Attention:
There can be no spaces between the variable name and the equals sign, which may be different from any programming language you are familiar with.
At the same time, the name of the variable names must follow the following rules:
The first character must be a letter (a-z,a-z).
You can use an underscore (_) without spaces in the middle.
Punctuation cannot be used.
You can't use the keywords in bash (you can see the reserved keywords using the help command).
Ii. Use of variables
Echo ${your_name}
Note: It is a good programming practice to add curly braces to all variables.
Third, redefine variables
Myurl= "http://see.xidian.edu.cn/cpp/linux/"
Echo ${myurl}
Myurl= "http://see.xidian.edu.cn/cpp/shell/"
Echo ${myurl}
Note: The second assignment cannot be written $myUrl = "http://see.xidian.edu.cn/cpp/shell/" and the dollar sign ($) is used when using variables.
Four, read-only variables
Myurl= "http://see.xidian.edu.cn/cpp/shell/"
ReadOnly Myurl
Myurl= "http://see.xidian.edu.cn/cpp/danpianji/"
Run the script with the following results:
/bin/sh:name:this variable is read only.
V. Delete variables
The variable cannot be used again after it has been deleted; The unset command cannot delete a read-only variable.
Unset variable_name
Vi. Types of variables
When you run the shell, there are three different variables:
1) Local Variables
Local variables are defined in a script or command, only valid in the current shell instance, and other shell-initiated programs cannot access local variables.
2) Environment variables
All programs, including shell-initiated programs, can access environment variables, and some programs require environment variables to keep them running properly. Shell scripts can also define environment variables when necessary.
3) Shell variables
Shell variables are special variables that are set by the shell program. Some of the shell variables are environment variables, some of which are local variables that guarantee the shell's normal operation.
"Shell Programming" 2, syntax