Linux shell notes

Source: Internet
Author: User

1.> file
If there is no command before, shell will create an empty file (with a length of 0 characters). If the file already exists, its content will be lost.

2. You can type multiple commands in one line, and separate them with good scores.

3. If the command is followed by an & symbol, the command is sent to the background for execution. That is to say, the command does not occupy the terminal and can continue to process other tasks.

4. The $ character is a special character of shell. If $ is followed by a valid variable name, shell treats it as a command to replace the value stored in the variable here. The expression can be written to $ (expression )).

5. The shell variable $ # contains the number of parameters entered in the command line.

6. $ * Can reference all parameters passed to the program. It is usually useful in programs with uncertain parameters or variable parameter numbers.
"$ @" Is replaced with "$ n". Here, the double quotation marks before and after $ @ are indispensable. If not, the variables $ @ and $ * are identical.

7. If you want to pass more than nine parameters to a program, you cannot use the $10, $11 methods to obtain 10th and later parameters. The format is $ {n.

8. shell automatically sets the exit status of the last executed command to the shell variable $? .
$ Cp phonebook phone2
$ Echo $?
$0
0 operation successful, non-0 operation failed

9. The internal command test is used to test one or more conditions in the if command, in the format of test expression.
-N string detection string is not empty to true
-N string detection string is null to true
Another mode of the test Command [expression]
-Eq equals
-Ge is greater than or equal
-Gt greater
-Le is less than or equal
-Lt is less
-Ne is not equal
File judgment
-D is the Directory
-E exists
-F: Common File
-R readable File
-S length is not 0
-W Writable Files
-X Executable File
-L link file
Logical judgment
! Non-logical
-A logic and
-O logic or

10. Parentheses ()

11. else Structure
If command1
Then
Command
Else
Command
Fi

12. Run the Internal Command exit to terminate the execution of the shell program immediately. Exit n is the exit status to be returned, not the exit status of the last command.

13. elif Structure
If command1
Then
Command
Elif command2
Then
Command
Else
Command
Fi

14. case Structure
Case value in
Pat1) command
Command
...
Command ;;

Pat2) command
Command
...
Command ;;
...
Patn) command
Command
...
Command ;;
Esac

The special characters in the case statement specify the matching mode:
? Represents any character
* Indicates zero or several arbitrary characters.

15.-x program debugging options
Sh-x program name program parameters

16. Empty command:
The objective is to do nothing, and is mostly used for conditional statements.

17. & | Structure
& If command1 & command2 is written to any location where shell commands are required, execute command1 first. If the returned exit status is 0, execute command2. If the return exit status of command1 is not 0, skip command2.
| The structure function is similar. The difference is that the second command is executed only when the exit status of the first command is not 0.

Pipeline lines can be used on both sides of this structure. If it is used on the left, the exit status of the last command in the MPs queue is detected.

18. for command
For var in word1 word2... wordn/filenames [1-n]/$ *
Do
Command
Command
...
Done

19. while command
While command1
Do
Command
Command
...
Done
While is often used together with the shift command. Shift command to move the location variable down (that is, $ n to $ N-1), and $ # decrease.

20. until command
Until command1
Do
Command
Command
...
Done
Opposite to the while Mode

21. sleep n programs are suspended for n seconds.

22. break n and continue n exit from the loop.

23. PATH
PATH is the directory to be searched by shell during command execution. These directories are separated by colons {:}.

24. exec command
Exec program replaces the current program with a new shell

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.