In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to understand Shell script to define variables and reassign values", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to understand Shell scripts to define variables and reassign values".
Shell supports custom variables.
Define variable
When you define a variable, the variable name is not marked with a dollar sign ($), such as:
The code is as follows:
VariableName= "value"
Note that there can be no spaces between the variable name and the equal sign, which may be different from all the programming languages you are familiar with. At the same time, the naming of variable names must follow the following rules:
The first character must be a letter (a murz.Amurz).
There can be no spaces in the middle, you can use an underscore (_).
You cannot use punctuation.
You cannot use keywords in bash (you can view reserved keywords with the help command).
The curly braces outside the variable name are optional, whether to add them or not, and the curly braces are added to help the interpreter identify the boundaries of the variable, as in the following case:
The code is as follows:
For skill in Ada Coffe Action Java
Do
Echo "I am good at ${skill} Script"
Done
If you don't add curly braces to the skill variable and write it as echo "I am good at $skillScript", the interpreter will treat $skillScript as a variable (its value is empty), and the code execution result will not be what we expected.
It is recommended to add curly braces to all variables, which is a good programming habit.
Redefine variables
Defined variables can be redefined, such as:
The code is as follows:
Your_name= "tom"
Echo $your_name
Your_name= "alibaba"
Echo $your_name
It's legal to write this way, but note that you can't write $your_name= "alibaba" on the second assignment, but only add the dollar sign ($) when using variables.
At this point, I believe you have a deeper understanding of "how to understand Shell script to define variables and reassign values". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.