Learn about the--shell script for Linux with brother Bird

Source: Internet
Author: User

From the programmer's point of view, the shell itself is a program written in C language, from the user's point of view, the shell is the user and the Linux operating system communication Bridge. The user can either enter command execution or use shell scripting to do more complicated operations. In the field of system management, shell programming can not be neglected. Earlier I made a preliminary understanding of shell programming, and now summarized as follows;

Mind Mapping:

The knowledge is divided into two parts:

Basic Knowledge:

In the basic knowledge I divided it into: The execution method, the expression, the variable and the judgment type four parts. 1, the implementation method is in the Linux Shell File Execution command, with more natural will not be a problem. 2, for the operation of which explained (()), the basic statement is a variable =$ ((expression)), where the result is often used as the basis for the judgment of the statement, it will get a return value, that is, the variable $? Its value of 0 indicates that the execution of the statement was successful, and not 0 indicates that the statement failed. Declare is used to declare a variable, which can later indicate the type of the variable, for example:-I. Similarly let can also give the variable a corresponding value, through the expression. 3, for variables where the return value $? Already mentioned before, for the default variable $#, these default variables are typically used for the representation of each field in each row based on a criterion. Previous blogs have been mentioned in the document layout. 4, the judgment has test function, it can detect the relevant properties of the system files, a very useful command, can be followed by a lot of parameters, related parameters to learn to use-HELP or man page to inquire and learn. There is the use of [], for [] to make some expressions of judgment, for the result of the judgment, it will also get a return value, so also as a judge in the statement to perform some related operations.

write the syntax:

See here and Early Learning C language and VB language have a lot of similarities, but there are many differences, the bottom of the summary to see their usage.

conditional judgment statement;If...then statement:

If followed by a judgment condition, then followed by the statement to execute, the same structure can be extended to the following:

If condition Then

EXECUTE statement

Elif condition Then

EXECUTE statement

Else

EXECUTE statement

Fi

CASE...ESAC statement:

function is similar to the switch statement in C. The specific structure is as follows:

case$ variable name in

Name of the first variable)

EXECUTE statement

;;

Second name of the variable)

EXECUTE statement

;;

*)

Other cases Execute statements

;;

Esac

function

function function, which is the same as the function function in the pre-learning. However, there are differences in structure, as follows:

Function name () {

function body

}

Loop statement:While/untildo Done

In fact, while dodone statements and until do-do statements are similar to an indefinite number of loops, just given the conditions, VB, the structure of contact, the following:

While/until [Judging type]

Do

EXECUTE statement

Done

The difference is that while the judgment does not immediately terminate the loop, and the until is to terminate the loop when the condition is established.

For...do...done

This cycle differs from the first two in that the number of cycles is known and the structure is as follows:

For variable in content 1 content 2 ...

Do

EXECUTE statement

Done

In the process of looping, the value of the content n is assigned to the variable to execute the following statement, of course, the expression of the content can be different, otherwise the variable is more difficult to express, for example, with (SEQ 1 100) represents 1 to 100.

Another way of structuring is as follows:

for (initial value; limit value; execution step))

Do

EXECUTE statement

Done

This is more similar to the for loop structure in which we touch in C and VB statements.

  

General statement:

At this point, I have a preliminary understanding of shell script, and later to continue to learn shell programming, file programming, serial programming, process and threading related knowledge and application, and hardware slowly combine to do some related processing and operation, the road behind is still very long, to learn a lot of things, Look forward to that a vision, can use their knowledge to repay the community, for more people to serve, to the community where there is a need to contribute their own contribution to the power is a happy thing, I believe the future will have a place for me to benefit others!!

Learn about the--shell script for Linux with brother Bird

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.