1. Declaration of variables
Name= "Blacksonny"
Note://variable definition does not add $, the variable and equal sign cannot have spaces between
Variable naming 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 with the help command)
2. Using variables
If you want to use a variable, add $ to it before the variable, and we recommend using ${name}
such as: $name
1 #!/bin/bash2#description: Use variable3#Author: Blacksonny 4 #Copyright (c) 5 #Script follows here: 6 7 name="blacksonny"8echo $name 9echo ${name}
The above code then outputs Blacksonny at the same time, where {} is optional and is generally used to define the bounds of the variable
The following code distinguishes between variables and programm, and no person can get the value of a variable
for inch Java Php Android IOS do Echo " I'll study ${book}programm " Done
3, the variable is redefined, the shell allows to redefine the variable, as with the method of defining the variable, just re-assign the original variable value can be
4. read-only variables
Define a read-only variable by using the ReadOnly keyword
number=1323readonly numbernumber=1333
The run var.sh result is: "./var.sh: Line 24:number: read-only variable", prompting that this variable is not allowed to be modified.
5. Delete variables
Use unset var_name to delete variables
6. Variable type
1) Local Variables
2) Environment variables
3) Shell variables
Use of variables in the shell