The shell supports custom variables.
Defining variables
When defining a variable, the variable name does not have a dollar sign ($), such as:
Variablename= "Value"
Note that 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).
Examples of variable definitions:
hello= "World"
huawei= "Pit Daddy"
caoliu=1024
Using variables
With a defined variable, just precede the variable name with a dollar sign ($), such as:
caoliu=1024
Echo $caoliu
Echo ${caoliu}
The curly braces outside the variable name are optional, plus the curly braces are used to help the interpreter identify the bounds of the variable, such as the following:
#vim for.sh
For Caoliu in Caoliu are so Niubi
Do
echo "All the world Otaku say ${caoliu}"
Done
Give executable permissions and execute
#chmod +x for.sh
#./for.sh
All the world's otaku say Caoliu.
All the world's otaku say is
All the world's otaku say so.
All the world's otaku say Niubi.
caoliu. as a variable (whose value is null), the result of the code execution is not what we expect it to look like.
It is a good programming habit to add curly braces to all variables.
This article is from the "8159085" blog, please be sure to keep this source http://8169085.blog.51cto.com/8159085/1793195
03. About the shell variables.