In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Introduction-basic Shell script 1, basic introduction in the daily work environment, there are often large quantities of repetitive information or data to be processed. As an administrator, it can be very troublesome and error-prone if you don't process this kind of data in large quantities. So at this point, Shell scripts are needed to batch process the data and automate the assigned tasks. Shell actually acts as a translator in a computer to convert human language into a binary language that the computer can recognize. See figure 1.1. We save the commands sequentially in an execution file, and we can also think of writing script commands as a journal, because the computer executes in the order in which the commands are written. Second, script parameters, command introduction 2.1.There are four ways to execute shell scripts, one of which is:. / the path of the script (absolute path or relative path). When you use this method again, make sure that the script file you want to execute has execution permissions, as shown in figure 1.2. Scripts that do not have execute permissions are not green, and scripts that have execute permissions are green. In general, if you want to execute a script in this way, you should make sure that you have the permission to execute it in advance, chmod + x script name. Method 2: the path of sh / script (absolute path or relative path). This method does not require script files to have execute permissions. Method 3: the path of source / script (absolute path or relative path). This method still does not require the script to have execute permission. Method 4:. The path of / script (absolute or relative path). This method still does not require the script to have execute permission. Summary: the above four methods do not need to execute files with executable permissions except. /. 2.2: the composition of the script 1. The suffix of the script is: .sh ends. See figure 2.12. When you write the script name, you need to write the script with #! / bin/bash starts with the first line. 3. If a statement begins with #, then the statement will not appear in the operation of the script, that is, the comment information. 4. In addition to the above, the most important part of the script is the executable statements, that is, commands, which the computer executes one by one according to the commands written by the user. (3) there are four types of variables acting on type variables: custom variables, environment variables, location variables and predefined variables. 1. A custom variable is a user-defined variable. After the user defines one for it, the value is stored in the computer's memory. If the user assigns a value to the same variable again, the value of the variable will change. See figure 3.1.1 pay attention! User-defined variables must start with a letter or an underscore "_" otherwise they are not variables. You need to use the $symbol when declaring variables. two。 Environment variables are set up within the computer system, as shown in figure 3.1.2 of PATH. The general environment variable name cannot be changed, but its contents can be changed. 3. The location environment variable is a parameter passed to the script. It is valid only if you enter after the name of the script. In the script, the location environment variable is represented by $n, and n represents the number 1x 9, which indicates the position after the script. 4. Predefined variables are pre-set variables for users, and users cannot change or assign values to these variables. Such as * $#, $?, $0 million *, and so on. Commands and symbols commonly used in scripts the following mainly introduces the use of some commands and symbols commonly used in scripts. 1.echo: for the output statement, echo "content", display the contents in quotation marks on the console. two。 Redirect symbol, which usually assigns the data after the execution of the script to a file. The main slave orientation symbol 3. The pipe symbol, "|", generally gives the result of the command on the left side of the symbol to the command on the right to continue processing. Form: command 1 | Command 2 |. . 4. Quotation marks, double quotation marks "", single quotation marks'', reverse apostrophes ``. Double quotation marks: special symbols, such as $, are allowed. Single quotation marks: invalidates internal special symbols. Reverse apostrophe: internal input is a command. 5.read-p: input from the keyboard to assign values to variables. Enter a paragraph after the read command to guide the user to enter the corresponding content to assign a value to the variable. 6.expr operation, generally can be calculated: addition, subtraction, multiplication, division and remainder. The corresponding symbols are: +, -,\, /,%. Its usage is: addition: expr a + b. Subtraction: expr a-b. Multiplication: expr a\ b. Division: expr a / b. Expr a% b. (5) the small summary section mainly introduces the working environment of the Shell script, the basic format of the script, the type and usage of variables and some basic instructions. Shell script is the top priority of automation, and the student number Shell script is very important. Therefore, the symbols and commands mentioned above are some of the most commonly used.
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.