In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
1. Shell defines the rules that variables need to follow.
In Shell programming, there is no need to declare variables in advance, and 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 use the help command to view reserved keywords)
Second, shell variable assignment
When you need to assign a value to a variable, you can write:
Variable name = value
Third, the reference of shell variable
To take the value of a variable, simply precede the variable name with a $(note: when assigning a value to a variable, do not leave spaces on both sides of the "="). For example:
#! / bin/sh
# assign values to variables:
A = "hello world" # No spaces can exist on either side of the equal sign
# print the value of variable a:
Echo "An is:" $a
Note: the # sign above is a note, which will be discussed later.
Pick your favorite editor, type the above, save it as a file first, then execute chmod + x first to make it executable, and finally type. / first to execute the script. The output is as follows:
An is: hello world
Sometimes variable names may be confused with other words, such as:
Num=2
Echo "this is the $numnd"
The above script does not output "this is the 2nd" but "this is the"; this is because shell searches for the value of the variable numnd, which actually has no value at this time. At this point, we can use curly braces to tell shell that the num variable is to be printed:
Num=2
Echo "this is the ${num} nd"
The output result is: this is the 2nd
Note: the default assignment for shell is a string assignment. For example:
Var=1
Var=$var+1
Echo $var
What is printed is not 2 but 1: 1. In order to achieve the desired effect, there are several ways of expression:
Let "var+=1"
Var=$ [$var+1]
Var= `expr $var + 1` # pay attention to the spaces on both sides of the plus sign, otherwise the value will be assigned as a string.
Note: the first two methods are effective under bash and will make errors under sh.
Let represents a mathematical operation, expr is used for integer operation, each item is separated by a space, and $[] calculates the result first and then outputs the expression in square brackets as a mathematical operation.
There are many variables in the Shell script that are automatically set by the system, which we will explain when we use them. In addition to ordinary shell variables that are valid only within scripts, there are also environment variables, that is, those that are created by exp
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.