Shell programming-Day 2

Source: Internet
Author: User

Ls-l dir1 | WC-L.

1. While condition; do done // () [] Test
2. Until is the same as above. It is executed only when the condition is not true.
3. /Dev/null: Unix black hole. Used to clear the file CAT/dev/null> XX find-name a.txt 2>/dev/null
4. Note: After the trap question continue jumps out of the loop, the printed items are left in the buffer zone and the results are not printed.
5. Command list & |, whether the execution of the last command depends on the success of the previous command.
6. Statement block {}: (ls "$1") & {echo "$1 ".......}
7. Function 1. Function fun1 {} fun1 () {} Note: The function has no return value. You can directly write the function name by calling it. . Declare-F view all drop Functions
The shell function is a new shell process for shell, so passing the parameter: fun1 1 2 3, $0 is permanently unchanged, and the location parameter after $1 is partial in the function, it is still the location parameter of the main program.
8. Shell programming is based on commands, so you should always think about writing code in the command format.
9. The return value in the function is the return code, which must be an int line and cannot be of another type. A maximum of or 0 represents the result. If Val = $ (fun), the output is: what the function outputs.
10. In Shell, any command has a return code and must have a -- because it has a return code by default. (Use the last code as the return value)
11. Adding () indicates executing in the sub-shell; otherwise, executing in the current shell.
12. If you have to return a function, you can only use global variables. There is no other way. Fortunately, the variables in the function are global by default, and the variables modified with local are the local variables of the function.

$ (Fun) is the output of ECHO, not the return value.
13. A common function call does not start a new process. Calling shell will start a new process. A. Sh exec A. Sh (Exec won't create a new process)
14. Fork () exec source. These four methods are used to execute the sub-shell. The first two methods will create a new shell program, and the last two will be executed under the current shell.

15. Export to the output variable so that the variable can take effect in the sub-shell.

16. In the system, the process is a tree, and they are related (Parent and Child ...)

17. built-in commands (viewed using enable): these commands are loaded into the memory at Shell startup. For example, PWD echo external command: You need to configure its external program through path.

18. Jobs view the background program. FG % n bg % N Ctrl + z hangs .. We recommend that you use printf for ECHO-e-n (Note: spaces are not allowed in % s, because two parameters are replaced, because spaces exist in the middle)

19. Note: shell programming is based on a set of commands. Therefore, unlike other programming speech, it basically uses spaces to express its parameters and recognition. This is the programming in the Command form.

20. Eval: Use a string as a command. Try not to use it and there are risks.

21. Set to reset the location parameter. Set $ (date) echo $2, set-O unset delete a variable

22. Shift shifts all the location parameters by one, and the original value of $1 is discarded. Haha, $0 remains unchanged forever.

23. In many cases, the process ends with a signal. Haha

24. Trap Command: Specifies the action to be taken when the signal is received. Trap-sigout-, an integer of the trap command signal, indicates that the default response is used to respond to the signal.

25. In shell: the colon indicates an empty statement and also indicates logical truth.

26. $ process no. $? Return Value of the previous command

27. Exit N; 0 Success 1-255 error message 126 no permission 127 command not found 128 do not signal interrupt

28. Find path option test part of the Action Section

29; use; multiple commands can be separated into the same line; signal: interrupt technology; tar-CVF shell.tar * tar-TF shell.tar

30. $ () ''command replacement; process replacement:> Redirection; grep option regular file | path

31. Special element: ls-L | grep-e a [[: blank:] command line. Escape all special characters. Or use "" to escape.

32. awk tool: = gawk, awk-F' {print $1} '/etc/passwd begin {}/matching of the Main book: Execute backdoor braces/{} end {} My. awk file. The front and back blocks are executed once each time. Execute one row in the middle. Regular part. If the matching is successful, execute {}.

33. graphical language tool: Dialog gdialog

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.