Home Operation and Maintenance Linux Operation and Maintenance Detailed explanation of advanced programming of shell scripts

Detailed explanation of advanced programming of shell scripts

Jul 24, 2017 pm 03:33 PM
shell programming Script

0. Basic knowledge required for shell scripts

 -vi/vim editor commands, including vimrc settings;

 -Linux command basics

 -Network services ( nfs, rsync, inotify, lanmp, sersync, ssh key) batch distribution management

1. Introduction to shell script

 1.1 What is shell

 1.2 What shell script

 1.3 The role of shell programs in operation and maintenance work

 1.4 Types of scripting languages

 1.4.1 Types of shell script languages

1.4.2 Other commonly used script languages 

 1.5 OS default shell

 1.6 Creation and execution of shell script scripts

2. Shell variables from shallow to deep

2.1 Variable type

 2.2 Environment variables

 2.3 Customized environment variables (global variables)

 2.4 Display and cancel environment variables

 2.5 Local variables

 2.5.1 Define local variables

 2.5.2 Special variables

 2.5.3 Internal variables

 2.5.4 Variable substring operations

  2.5.5 Numerical calculation of variables

3. Conditional test

 3.1 Test statement

 3.1.1 Conditional test syntax

 3.1.2 File test Operator

 3.1.3 String test operator

 3.1.4 Integer binary comparison operator

 3.1.5 Logical operator

3.2 Conditional test example

 3.2.1 File test example

 3.2.2 String test example

 3.2.3 Integer test example

 3.2.4 Usage of test command testing

 3.2.5 Examples of logical operators

4. Branch and loop structures

 4.1 if statement 

 4.1.1 if condition Sentence syntax description

 4.1.2 If conditional sentence example

 4.1.3 Multi-judgment conditional if statement (&&, ||)

 4.2 case conditional sentence

 4.2.1 Case conditional sentence syntax

 4.2.2 Case structure conditional sentence self-writing example

 4.2.3 Case structure conditional sentence system script example

 4.2. 4 System benchmark script

 4.3 When type loop and until type loop

 4.3.1 When type and until type loop syntax

 4.3.2 Basics of when type and until type loop Example

 4.3.3 Advanced production practical example expansion

 4.4 for loop structure

 4.4.1 for loop structure syntax

 4.4.2 for loop structure Basic example

 4.4.3 In-depth example of for loop structure

 4.4.4 Advanced example of for loop structure

5. break continue exit

 5.1 break continue exit comparison

 5.2 break continue exit example

6. Shell function

 6.1 shell function syntax

 6.2 shell function execution

 6.3 Shell function example

7. shell script debug

 7.1 Examples of common script errors

 7.1.1 The if conditional sentence lacks the if ending keyword

 7.1. 2 Missing keyword error in the loop structure

 7.1.3 Paired symbols are missing, causing an error

 7.1.4 There are no spaces at both ends of the square brackets [], causing an error

 7.2 Shell script debugging skills

 7.2.1 Use dos2unix command to process scripts

 7.2.2 Use echo command to debug

 7.2.3 Use bash command parameters to debug

 7.2.4 Use the set command to debug part of the script content

8. Shell script development habits, specifications, read-only

 8.1 Naming convention

 8.1.1 Version and run Rigel

 8.1.2 Variable naming

 8.1.3 Function naming

 8.1.4 Script (module) naming

 8.1.5 Temporary File naming

8.2 Code style specification

8.2.1 Code framework

8.2.2 Function specification

8.2.3 Conditional statements and loops

 8.3 Comment specifications

 8.3.1 File/module comments

 8.3.2 Important function comments

 8.3.3 Good habits of writing comments

8.4 Reference symbol usage specifications

8.5 Log specifications

8.6 Interface file specifications

8.7 Configuration specifications

8.7.1 Configuration file specifications

 8.7.2 Inspection of configuration items

8.8 Script storage specifications

8.9 Supplementary specification development habits

9. Configuration adjustment and optimization of shell development environment

 9.1 Set up SecureCRT terminal vim shell environment configuration

 9.2 vim shell environment function

 9.2.1 SecureCTR terminal vim automatically adds copyright function information

 9.2.2 vim editing Automatic completion function of paired brackets in the vim editor

 9.2.3 Automatic completion function of functions and other functions in the vim editor

 9.2.4 Automatic indentation, highlighting, etc. in the vim editor

 9.3 vim shell environment configuration.vimrc implementation code and parameters

 

 7.2 shell script debug skills

The above is the detailed content of Detailed explanation of advanced programming of shell scripts. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Remove duplicate values ​​from PHP array using regular expressions Remove duplicate values ​​from PHP array using regular expressions Apr 26, 2024 pm 04:33 PM

How to remove duplicate values ​​from PHP array using regular expressions: Use regular expression /(.*)(.+)/i to match and replace duplicates. Iterate through the array elements and check for matches using preg_match. If it matches, skip the value; otherwise, add it to a new array with no duplicate values.

The difference between PHP functions and Shell functions The difference between PHP functions and Shell functions Apr 24, 2024 pm 06:39 PM

The main differences between PHP functions and Shell functions are security (PHP functions are more secure), reliability (Shell functions vary by operating system), functionality (Shell functions are more powerful but limited by the shell), and performance (PHP functions are usually faster) and complexity (Shell functions are more complex). They are both used for file system, process and command operations, but PHP functions are built-in, while Shell functions are called through an external shell. Therefore, in server file download scenarios, the file_put_contents() function is safer, while the wget command is more flexible.

What is programming for and what is the use of learning it? What is programming for and what is the use of learning it? Apr 28, 2024 pm 01:34 PM

1. Programming can be used to develop various software and applications, including websites, mobile applications, games, and data analysis tools. Its application fields are very wide, covering almost all industries, including scientific research, health care, finance, education, entertainment, etc. 2. Learning programming can help us improve our problem-solving skills and logical thinking skills. During programming, we need to analyze and understand problems, find solutions, and translate them into code. This way of thinking can cultivate our analytical and abstract abilities and improve our ability to solve practical problems.

Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Problem-Solving with Python: Unlock Powerful Solutions as a Beginner Coder Oct 11, 2024 pm 08:58 PM

Pythonempowersbeginnersinproblem-solving.Itsuser-friendlysyntax,extensivelibrary,andfeaturessuchasvariables,conditionalstatements,andloopsenableefficientcodedevelopment.Frommanagingdatatocontrollingprogramflowandperformingrepetitivetasks,Pythonprovid

Collection of C++ programming puzzles: stimulate thinking and improve programming skills Collection of C++ programming puzzles: stimulate thinking and improve programming skills Jun 01, 2024 pm 10:26 PM

C++ programming puzzles cover algorithm and data structure concepts such as Fibonacci sequence, factorial, Hamming distance, maximum and minimum values ​​of arrays, etc. By solving these puzzles, you can consolidate C++ knowledge and improve algorithm understanding and programming skills.

Build browser-based applications with Golang Build browser-based applications with Golang Apr 08, 2024 am 09:24 AM

Build browser-based applications with Golang Golang combines with JavaScript to build dynamic front-end experiences. Install Golang: Visit https://golang.org/doc/install. Set up a Golang project: Create a file called main.go. Using GorillaWebToolkit: Add GorillaWebToolkit code to handle HTTP requests. Create HTML template: Create index.html in the templates subdirectory, which is the main template.

The Key to Coding: Unlocking the Power of Python for Beginners The Key to Coding: Unlocking the Power of Python for Beginners Oct 11, 2024 pm 12:17 PM

Python is an ideal programming introduction language for beginners through its ease of learning and powerful features. Its basics include: Variables: used to store data (numbers, strings, lists, etc.). Data type: Defines the type of data in the variable (integer, floating point, etc.). Operators: used for mathematical operations and comparisons. Control flow: Control the flow of code execution (conditional statements, loops).

Unleash Your Inner Programmer: C for Absolute Beginners Unleash Your Inner Programmer: C for Absolute Beginners Oct 11, 2024 pm 03:50 PM

C is an ideal language for beginners to learn programming, and its advantages include efficiency, versatility, and portability. Learning C language requires: Installing a C compiler (such as MinGW or Cygwin) Understanding variables, data types, conditional statements and loop statements Writing the first program containing the main function and printf() function Practicing through practical cases (such as calculating averages) C language knowledge

See all articles