The shell supports custom variables.
Defining variables
When you define a variable, the variable name is not a dollar sign ($), such as:
Copy Code code as follows:
Note that there can be no space between the variable name and the equals sign, which may be different from any programming language you know. At the same time, the name of the variable must follow the following rules:
• The first character must be a letter (a-z,a-z).
• Cannot have spaces in the middle, you can use an underscore (_).
• Punctuation can not be used.
• You cannot use keywords in bash (available help commands to view reserved keywords).
The curly braces outside the variable name are optional, plus all rows, and curly braces are designed to help the interpreter identify the bounds of the variable, such as the following:
Copy Code code as follows:
For skill in Ada coffe Action Java
Todo
echo "I am good at ${skill}script"
Done
If the skill variable is not curly braces, written as echo "I am good at $skillScript", the interpreter takes $skillscript as a variable (its value is empty), and the code execution results are not what we expect.
It is a good programming practice to recommend all variables plus curly braces.
Redefining variables
Defined variables that can be redefined, such as:
Copy Code code as follows:
Your_name= "Tom"
Echo $your _name
Your_name= "Alibaba"
Echo $your _name
This is legal, but note that the second assignment can not write $your_name= "Alibaba", the use of variables to add the dollar ($).