In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Shell Script Concept
1. Save the commands to be executed in sequence to a text file
2. Give the file executable permission and it can run.
3, can be combined with a variety of shell control statements to complete more complex operations
Shell Script Application Scenario
1. Repeatable operation
2. Batch transaction processing
3. Automated operation and maintenance
4. Monitoring of service operation status
5. Timing task execution
Perfect shell script composition
1. Script declaration
2. Executable statements
3. Comment text
Shell's Role--Command Interpreter,"Translator"
Execution script file method complete
Method 1: Script file path (absolute and relative)
Method 2: sh script file path
Method 3: Source Script File Path
Method 4:
[root@localhost ~]#. first.sh
Summary:
1. Except.../ First.sh needs to be assigned execution permission before it can be executed, and the rest of the execution file commands do not need to be assigned and can be executed directly;
2.sh.first.sh vs./ First.sh does not change the current directory location after executing the file
interactive hardware device
Standard Input: Data received from the device as input by the user
Standard Output: Output data to the user through the device
Standard Error: An execution error message is reported by this device
1. Redirect operations
2. Pipeline operation symbol "|"
Output the result of the command on the left as the target of the command on the right
awk: vertical recognition
The command in the figure can be converted:
awk -F: '{print $1,$7}'=awk -F":" What the variable '{print $1,$7}' does
1. Provide specific parameters for flexible management of Linux systems, with two layers of meaning.
Variable Name: Use a fixed name, preset by the system or defined by the user
Variable value: can change according to user settings and system environment changes
the type of a variable
1. Custom variables: defined, modified and used by users themselves
2. Environmental variables: maintained by the system and used to set the working environment
3. Position variable: pass parameters to script program through command line
4. Predefined variables: a class of variables built in Bash that cannot be modified directly
Define a new variable
Variable names start with a letter or underscore, case sensitive, all caps recommended
View variable names
Use quotation marks when assigning
Single quotes: Prohibited from quoting other variable values,$is treated as an ordinary character
Double quotes: Allow references to other variable values via the $sign
Reverse apostrophe: command replacement, extract the output of the command after execution
Input from keyboard assigns variable values
Set the scope of a variable
The two formats can be mixed
Operations on integer variables
Common operators
Addition: +
Subtraction: -
Multiplication: \ *
Division: /
Modulus (remainder): %
environment variable
1. Created by the system in advance to set the user's working environment
Configuration files: /etc/profile,~/.bash_profile
2. Environment variables created
PWD、PATH
USER、HOME、SHELL
position variable
1, expressed as $n, n is a number between 1 and 9
[root@localhost ~]# ./ myprog.sh one two three four five six
./ myprog.sh:$0(name of currently executing process)
one:$1 (1st position parameter)
two:$2 (2nd position parameter)
six:$6 (6th position parameter)
predefined variables
●$#: Number of positional variables in the command line
●$*: Contents of all position variables
●$?:The status returned after the execution of the previous command. When the returned status value is 0, it indicates execution.
Line normal, non-zero value indicates execution exception or error
●$0: Name of currently executing process/program
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.