Li Sanhu, the second International Class 2 of the 2010 International Software Institute of Wuhan University, hasn't written any logs for a long time. Today, I wrote one.
I recently feel that the book is still very classic for learning a new language. Although it is unpleasant to start with an identifier, however, it is found that the structure in the book is correct if you want to quickly master a language. Of course, it's just about the structure of the book. It's easy to have some content. For shell programming, let's talk about the variable name first. Just like javascript, you don't need the name, just use it directly, just assign values. Variables can be used in the following ways: 1. $ varname 2. $ {varname }. The second is mainly for a special case. For example, if you want to print 2nd, the 2 is stored in the variable two, but is connected with nd, the first one cannot be used, use the second method. Let's look at the shell data types. There is only one string type. The delimiter used by shell to program each statement: a line break or a semicolon. the braces can separate several statements with semicolons as a whole, that is, the statement block. Shell programming is process-oriented rather than object-oriented. Therefore, you must consider the Declaration and use of functions. Format
functionname(){# inside the body $1 is the first argument given to the function# $2 the second ...body}
You can use functionname directly when using it without brackets. If there is a parameter, the function declaration and use do not need brackets, just use spaces to separate each parameter before the statement delimiter. One thing to note is that the shell must be used after being declared first. Like C and C ++, it is different from the Object-Oriented java. When a program functions, only the following statements are possible: common statements, loop statements, and condition branch statements. Common statements in shell: the above statements are similar. Loop statement: while expression; do loop body donefor variable name in expression 1 expression 2 expression 3 ......; Do Loop body done condition branch statement: In my understanding, this is divided into condition statements and branch statements. Of course, these two are essentially one thing. Condition Statement: if ....; then .... elif ....; then .... else .... fi uses the teacher's words to say that this fi is a spoof. Haha, if fi includes the spoof of case esac programmers below. Case... in...) do something here; esac this is a branch statement. For any procedural language, you should be able to quickly follow the above steps. The first step is to understand the declaration, use, type, and special features of each type, for example, there are many special characters in the shell string type, such as the difference between double quotation marks and single quotation marks, whether there are escape characters, wildcards, and so on. Step 2: function declaration and usage. This is almost the most important aspect of Procedural language. Step 3: Process Control statements are the usage and format of condition branch statements and loop statements. Of course, this is just a framework, and every kind of special feature should be checked. It is also the same if you try again. You must also learn how to use functions written by others, understand the documents written by others, know how to input parameters, get output, and what the functions do.