Shell learning notes, shell script Learning Guide

Source: Internet
Author: User

Shell learning notes, shell script Learning Guide

It's all a bit of fragmented knowledge. What do you need to write!

1. shell Script Parameters

C uses (int * argc, char * argv []) to process parameters, python sys. argv [0] (Script Name), sys. argv [1], sys. argv [2] and so on indicate each parameter. The shell script processes the command parameters as follows:

(1) $ # number of parameters passed to the script, excluding the script command itself. For example, to determine whether there are two parameters:


   #!/bin/bash   if [ $# != 2 ]; then                                                                                                                          echo "Error! should need 2 parameters!"       exit 1   fi


(2) $0 Script Name; $1, $2,... indicates the first parameter, the second parameter ,......

(3) $ * display all parameters passed to the script with a single string. This parameter can contain more than 9 parameters. For example:

If the script parameter is./test. sh arg1 arg2, execute echo $ * and the result is: "arg1 arg2"




(4) $ ID of the current process that the script runs.

(5) $! The ID of the last process running in the background.

(6) $ @ is the same as $ *, but it is enclosed by quotation marks and each parameter is returned in quotation marks. For example:


If the script parameter is. /test. sh arg1 arg2, the echo $ * command is executed, and the result is: "arg1" "arg2" and # *. Each parameter is a separate string.


(7) $-display the current options used by shell, which have the same functions as the set command. (Do not understand)

(8) $? Displays the exit status of the last command. 0 indicates no error, and any other value indicates an error. For example:


Ls./echo $? $? 0 indicates that the ls command is successfully executed.



2. Pipelines and redirection

Pipeline operator "|", outputs the correct output information from the command on the left, and does not directly process the information with stderr. Then, the command on the right is passed as stdin.


(1) pipeline commands only process the correct output of the previous command, without handling the error output;

(2) The command on the right of the pipeline command must be able to receive the standard input stream command. For example, cat test.txt | ls and ls do not support stdin. The data on the left is discarded.


$ cat |  test3.cpp  test2.cpp   test.c



The command on the left should have standard output> or> file on the right

The command on the left should have a standard input <or <The right side can only be a file

The pipeline triggers two sub-processes to execute "|", while the redirection is executed in one process.

3. shell and export
First, you must know that after a user logs on to linux, the system starts a User shell. Run the shell script in this shell to create a sub-shell. The sub-shell can share the environment variables of the parent shell, but the parent shell cannot share the environment variables defined in the sub-shell. The environment variables defined in the sub-shell are only valid in the sub-shell.

When executing a program in shell, shell provides a set of environment variables. export can be used to add, modify, and delete environment variables for subsequent programs. The variables set by export are valid only for this logon.

Syntax: export [-fnp] [variable name] = [variable setting value]


-F indicates the function name in [variable name.

-N: The specified variable is not deleted, but is not output to the execution environment of subsequent commands.

-P lists all environment variables that the shell assigns to the program. The default parameter is used.
For example:


Test @ ubuntu :~ /Code $ export // equivalent to export-pdeclare-x HOME = "/home/Test" declare-x LANG = "zh_CN.UTF-8" declare-x LANGUAGE = "zh_CN: en_AU: en_CA: en_GB: en_NZ: en_US: en "declare-x LC_ADDRESS =" zh_CN.UTF-8 "/* center omitted */declare-x TERM =" linux "declare-x USER =" Test "declare-x XDG_RUNTIME_DIR ="/run /user/1000 "declare-x XDG_SESSION_ID =" 1"
</pre><pre name="code" class="plain">Test@ubuntu:~/code$ export mytest="Hi"
<Pre name = "code" class = "plain"> Test @ ubuntu :~ /Code $ export declare-x HOME = "/home/Test" declare-x LANG = "zh_CN.UTF-8" declare-x LANGUAGE = "zh_CN: en_AU: en_CA: en_GB: en_NZ: en_US: en "declare-x LC_ADDRESS =" zh_CN.UTF-8 "/* center omitted */declare-x TERM =" linux "declare-x USER =" Test "declare-x XDG_RUNTIME_DIR ="/run /user/1000 "declare-x XDG_SESSION_ID =" 1 "declare-x mytest =" Hi"


Test @ ubuntu :~ /Code $ export-n mytestTest @ ubuntu :~ /Code $ export declare-x HOME = "/home/Test" declare-x LANG = "zh_CN.UTF-8" declare-x LANGUAGE = "zh_CN: en_AU: en_CA: en_GB: en_NZ: en_US: en "declare-x LC_ADDRESS =" zh_CN.UTF-8 "/* center omitted */declare-x TERM =" linux "declare-x USER =" Test "declare-x XDG_RUNTIME_DIR ="/run /user/1000 "declare-x XDG_SESSION_ID =" 1"

Because the environment variables added to the export are temporarily valid, they must be added to the file if they are permanently valid:



(1) Add a variable to the/etc/profile file, which is permanently valid for all users. For example:
# Vi/etc/profileexport CLASSPATH =./JAVA_HOME/lib; $ JAVA_HOME/jre/libexport PATH = "$ PATH:/home/Test" // Add data to the original PATH variable
(2) In the user directory. bash_profile (this file is in different linux systems and has different file names, some of which are. profile, which ends with profile and can be queried using man bash.) add environment variables to the file, which is permanently valid for this user. The usage is the same as above. Source FileName is used to read and execute the command in FileName in the current bash environment. This FileName does not have the execution permission. Note that the script in this command is in Execute in the current bash EnvironmentThe sub-shell is not generated, so the variables added by the script can also be shared by the current shell, which is not the same as directly executing the script to generate a sub-shell. The same script Test. sh:
#!/bin/bash     export mytest="Hi"
Run the command in source Test. sh mode, and the mytest environment variable can be added to the current shell environment. The direct execution in./Test. sh mode cannot. In addition, the source command is often replaced. Source Test. sh is equivalent to. Test. sh.



For Study Notes

How to write Chinese notes

How to write Chinese notes

As the saying goes, "It's better to remember with ink", and "it's better to write your mind over a thousand times ". The teacher makes the class clearer in class. If the students do not remember it, they will forget it later. Note-taking is an extension of memory for future review and searching. The more advanced the learning, the more important it is to remember. Students take notes while attending lectures in the classroom. They can be in the best learning status of brainstorming, hands-on, and ears. They can suppress the "thoughts" and make their attention highly concentrated, improve efficiency, and deepen their impressions. Note Taking can also speed up writing and save time. Teachers should teach students to take Chinese notes from the upper grades of primary school. When I was a child, students learned to take Chinese notes, which laid the foundation for future Chinese learning and other subjects, formed self-learning ability, and formed good study habits, and can be used for life.

How do I take Chinese notes? Students should write their preview notes, class notes, and some Chinese homework together in one book, collectively referred to as "Chinese notes ". In this way, the complexity can be simplified, which not only reduces the Learning Burden of students, but also reduces the burden of teachers' correction. There are both checks on students' previewing, feedback on classroom teaching, and acceptance of basic knowledge. The teacher can correct the Chinese notes and receive the effect of "three in one fell swoop.

It is best to use a 16-open "course preparation notebook" in a Chinese notebook. Draw two straight lines on both sides of each page and divide them into three parts. One copy on the left is about two characters in width, which is used for project recording and serves as a Directory Index. the other copy on the right is about one inch in width and is used for remarks. This part is used flexibly by students, note some difficult questions, your own comments, feelings, and learning methods. The content of this part is inconsistent. the widest and most important one in the middle is, the learning content is recorded in this section.

After the preparation is complete, the next step is how to remember. You can take Chinese notes in three stages:

1. Preparations before class

Before learning a new course, students should preview the course, and record the content learned in the course and the problems they cannot solve in the middle and right parts of the Chinese notes respectively. The words and words that can be solved through the tool book are all completed at this time, which is one of the three parts of the Chinese notes.

2. Lecture Notes

This is the most important part in Chinese notes. In a Chinese class, students need to take notes while taking lectures, record the content of the new course in the middle column, and record the content that can be corrected due to inaccurate understanding in the preview in the remarks column on the right. At this time, there are two points to note: first, students can't talk about it. After the course, the students write the content they want to remember on the blackboard; second, the students cannot write down all the words the teacher says. On the basis of understanding, they should listen and think, sum up the key points, and generalize them into key sentences or words, then write it to the Chinese notes, as long as the meaning is correct. When starting the training, the teacher should say slowly what needs to be recorded, and repeat the long sentences and important points one or two times. Keywords, new words, Homophone Words, and easy-to-mix and easy-to-error words to be remembered. Teachers should blackboard writing to prevent students' mistakes.

3. consolidation after class

After a Chinese lesson, students need to take notes. The questions that have been solved in the text should be followed up, and the missing parts should be supplemented. It is best to remember them in summary, the good words and good sentences in the article can also be excerpted based on interest. After the course is organized and modified, the students' understanding of the content is deepened and their understanding is improved. The content to be recorded after class also includes some exercise questions after the course, such as the words to be copied, the words to be interpreted, the words to be interpreted, the meanings of the key sentences to be understood, and the brackets, sentences. In this way, the content of each lesson is concentrated on the Chinese notes, so that the knowledge can be easily classified for review and search; students can save the additional effort to write their homework, and the Chinese notes can be handed over as homework; when correcting Chinese notes, the teacher not only accepted the basic knowledge of the course, but also checked the students' preview and lectures. During the training process, teachers should focus on students, solicit Students' Opinions, constantly improve their practices, and do not insist on consistency in form and content. This can cultivate students' creative and divergent thinking abilities.

Chinese classroom learning and guiding strategies

How to take study notes is the most effective?

1. 5R note Method
The 5R note method is also called the Kanai note method. It is named by the university name that generates the note method. This method is suitable for almost all lectures or reading classes, especially for lecture notes, 5R notes should be the best choice. This method is an effective method that combines recording, learning, thinking, and application. The procedure is as follows:
1. Record ). During the lecture or reading process, in the main column (the page of the notebook is divided into two parts: the left, the right, and the left, and the right, the secondary column) record as many meaningful arguments and concepts as possible.
2. Reduce ). After class, try to summarize these arguments and concepts briefly (simplified) in the memories column, that is, the secondary column.
3. Recite ). Cover the main column, and use only the note in the memories column to fully describe the content discussed in the class as much as possible.
4. Reflect ). Separate your own lectures, comments, experiences, and other content from the lecture content, write them in a separate part of a card or notebook, and add the title and index, it is compiled into outlines and summaries and divided into categories. And archive at any time.
5. Review (Review) takes about 10 minutes a week to quickly Review the notes. The main purpose is to first read the memories column and view the main column as appropriate.
This method can be used as an example for training when taking notes. On the basis of continuous proficiency in this section, it is then used in other subjects.
Ii. Symbolic record Method
The symbolic record method adds symbols next to the original texts of textbooks and reference books, such as straight lines, double lines, black spots, circles, curves, arrows, red lines, blue lines, triangles, boxes, landing signs, exclamation points, question marks, etc., to facilitate the identification of key points, deepen the impression, or raise questions. You can grasp what symbols mean, but it is best to form a stable symbol system. This method is suitable for self-study notes and preview notes. Pay attention to the following guidelines during operations:
1. Mark it after reading it. Do not mark a textbook before you finish reading the entire section or the part with a title and stop thinking. When reading this article, you need to determine whether the author is talking about a new concept or simply using different words to describe the same concept. You have to wait until you finish reading this section or part of it, in order to look back at the repeated content. This will prevent you from looking at things that seem important at a glance.
2. Be very good at choice. You don't need to underline a lot of projects or write a lot of projects at once. This will overload your memory, and force you to think about problems in several ways at the same time, which will also increase the burden on your thinking. You need to make less marks, but not less so that you have to read the entire page during review.
3. Use your own words. You should use your own words to write short notes in the blank area of the page. This is because your words represent your own thoughts. In the future, these words will become some powerful tips for the concepts described on this page.
4. concise. Underline some short but meaningful phrases, rather than strip them under a complete sentence. Note the blank spaces on the page to be concise and concise. They will be more impressive in your memory. It is easier to use when you recite and review.
5. Fast. It is impossible for you to use it for a whole day. You should first read it, then go back and review it, and quickly mark it, And then learn the next part of this chapter.
6. Neat. The symbols you have made should be as neat as possible, rather than gibberish. Otherwise, your future review and operations will be affected. When you review later, neat marks will encourage you to keep learning and save time, because neat marks help you quickly recall the original learning situation, it helps you easily and clearly understand the ideas in the book.
The methods for sorting and processing notes are as follows:
1. Recall. After class, take the time to review the relevant information in a timely manner. This is an important prerequisite for you to take notes.
2. Complete. The notes made in the class are followed by the speed of the instructor's lectures, and the speed of lectures is faster than the record speed, so your notes may be missing, jumping, or omitted, make timely repairs on the basis of memory to make the notes more complete.
3. Change. Carefully review your class notes and modify the incorrect words, sentences, and other inaccurate information.
4. editing. Use a unified serial number to arrange the content of the notes in a systematic and logical manner, indicate the numbers, and sort out the order of the notes.
5. points ...... remaining full text>

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: 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.