9, special characters of Linux

Source: Internet
Author: User
Tags arithmetic

The special symbols commonly used in the shell are listed below:#   ;      ;;      .       ,/\ ' String ' |   !      $   ${}   $?   $$ $* "String" * * *?   : ^ $# [email protected] ' command ' {} [] [[]] () (()) | | && {Xx,yy,zz,...} ~ ~+ ~-& \<...\> +-%= = = = a

01. # #!/bin/bash

The annotation character (comments); A=1 #a是等于1的

${#name} gives the length of name

${name#word} removes the smallest part that matches word from the head of name and then returns the remainder
${name# #word} Remove the longest part of word from the head of name and return the remainder
(Note, name is the variable name, Word is the string to match)

02, >   REDIRECT output symbols.
03, >> redirect output symbol, No new, append .
04, 2> error redirect output symbol, overwrite the original file contents.
05, 2>>   error redirect output symbol, no new, append . 0, 1, and 2 respectively indicate standard input, standard output, and standard error message output
06, *   Match any character.  
07,? matches any one character.   
08, |   Pipe symbol   (pipeline) . Explanation: Command1|command2, Command1 output as input to Command2, pipeline command accepts only standard input (standoutput).
09, & Background process characters.  
10, &&   logic and symbols. Usage: Command 1 && command 2 indicates that if command 1 executes successfully, continue with command 2.   
11, | | Logical OR symbolic. Usage: Command 1 | | Command 2 indicates that command 1 executes successfully, does not execute command 2, but executes command 2 if command 1 execution fails.

12,! Logical non-symbol (negate or reverse). Excludes the specified range. Example: LS a[!0-9] Example: conditional detection, using! = to represent "not equal"
13, [x-y] indicates a certain range.
14, "" double quotation marks (double quote) means that it contains the content as ordinary characters, but "$ \" a few symbols except.
15, "single quote " means that it contains the content as ordinary characters, no special exception.
16, $ variable, extract variables, such as Echo $HOME, to see the variable; in the regular expression, the beginning of the line.
The 17, \ Escape character is the meaning of converting a special character to its original normal character.
18, "anti-single quotation mark (backticks), indicating what it contains. typically used as an embedded command, this command executes first .

Date= ' Date +%y%m%d%h%m%s ' date +%f

19. Sequential command delimiter (separator).
20, < redirect the input character.
21, () indicates the overall execution of the order (Command Group)
Enclose a sequence of successive instructions in parentheses, which is called a command group for the shell.

      Example: (CD ~; vcgh= ' pwd '; echo $vcgh), the instruction group has an attribute, and the shell executes the set of instructions in order to generate Subshell. Therefore, the variables defined therein are used only for the instruction group itself

22, ^ Reverse selector, example: Grep-n ' ^[^a-za-z] ' wokao.txt,[] in the name of the reverse selector, [] outside the position is positioned at the beginning of the line.

23,. In the shell 1 dot represents the current directory, two dot represents the upper directory;

The file name starts with Dot and belongs to a special hidden file;

In RE, a dot represents a match to a character.

24,, (comma) often used in the operation as "Partition" use. T1 = ((A = 5 + 3, B = 7-1, c = 15/3))

25,/Slash (forward slash) when the path is represented;

In arithmetic, the symbol representing division;

26, (()) The function of this set of symbols is similar to the Let directive, and is used in arithmetic operations.

Two

1. {} curly braces:
Usage One: Wildcard extension
Eg:ls My_{finger,toe}s
This command is equivalent to a combination of the following commands:
LS my_fingers my_toes
Eg:mkdir {Usera,userb,userc}-{home,bin,data}
We will get Usera-home, Usera-bin, Usera-data, Userb-home, Userb-bin,userb-data,
Userc-home, Userc-bin, userc-data, these directories
Usage Two: Can be used for the construction of statement blocks, between statements separated by carriage return. If you want to use a single statement in some places (such as in and OR
or list) using multiple statements, you can construct a block of statements by enclosing them in curly braces {}.
eg
{
Grep-v "$cdcatnum" $strack _file > $temp _file
Cat $temp _file > $strack _file
Echo
Cat-n file1
} (Note: The four sentences in the curly braces above are enough to be a block of statements)
Usage three: Parameter extension
${name:-default} uses a default value (usually a null value) in place of the empty or unassigned variable name;
${name:=default} uses the specified value instead of an empty or unassigned variable name;
${name:?message} If the variable is empty or unassigned, the error message is displayed and the execution of the script is aborted while returning the
Out of code 1.
${#name} gives the length of name
${name%word} removes the smallest part that matches word from the end of name and then returns the remainder
${name%%word} removes the longest part that matches word from the end of name and then returns the remainder
${name#word} removes the smallest part that matches word from the head of name and then returns the remainder
${name# #word} Remove the longest part of word from the head of name and return the remainder
(Note, name is the variable name, Word is the string to match)
Usage three is useful when dealing with strings and unknown variables.

2, [] brackets:

Usage One: Wildcard extension:
Allow matching of any single character in square brackets
Eg:ls/[eh][to][cm]*
Equivalent to executing ls/etc/home (if there is a/eom directory, it is equivalent to executing ls/etc/home/eom)
Note: cannot be extended under the mkdir command
Usage two: Used for conditional judgment symbols:
The [] symbol can be interpreted as a soft link to the test command, so its usage can be fully referenced by test, replacing the test position with
[Can be.]
Eg:if ["$?"! = 0] equivalent to if test "$?"! = 0
Then echo "Executes error"
3, ' command ' anti-quote: ' command ' has the same meaning as $ (command), which returns the result of the current execution of the command eg: #!/bin/sh
For file in $ (ls f*.sh);d o
LPR $file
Done
Exit 0
This example implements the name of the file that extended f*.sh gives all matching patterns.
4, ' string ' single quote and ' string ' double quotation marks: If you want to include a space in a defined variable, you must use single or double quotation marks.
The difference between single and double quotes is that double quotes escape special characters and single quotes do not escape special characters
Eg: $ heyyou=home
$ Echo ' $heyyou '
$ $heyyou ($ not escaped)
Eg: $ heyyou=home
$ echo "$heyyou"
$ home (Obviously, $ escaped the value of the output of the heyyou variable)
5, $# its role is to tell you how much the total number of reference variables, $$ its role is to tell you the shell script process number;
$* displays all the parameters passed by the script in a single string. Equivalent to $ $ $ ...;
[email protected] is basically similar to $* (see serial number 7), but it is somewhat different when assigning values to an array;
$? The exit code of the previous command;
$-shows the current options used by the shell;
$! The process ID number that was last run in the background.
6, $ ((...)) Syntax: Evaluate an expression in parentheses eg:
#!/bin/sh
X=0
hile ["$x"-ne];d o
Echo $x
x=$ (($x + 1))
Done
Exit 0
7, the shell of several special parameter variables of the reference "$, $, $3......${10}, ${11}, ${12} ... : represents each parameter passed in by the script, and note that when the two-digit number is required
Arguments, the numbers are enclosed in curly braces.
[Email protected] List all parameters, each parameter is separated by a space
$*: Lists all parameters, separated by the first character of the environment variable IFS
8. List of commands: and list statement1 && statement2 && statement3 && ...:
Execute the latter command only if all previous commands have been successfully executed
or List statement1 | | Statement2 | | Statement3 | | ...:
Allows a series of commands to be executed until one command succeeds, and all subsequent commands are no longer executed
Eg:#!/bin/sh
Touch File_one
Rm-f File_two
If [-f File_one] && echo "Hello" && [-F File_two] && echo "There"
Then
echo "in If"
Else
echo "in Else"
Fi
Exit 0
The output of the above example is:
Hello
In Else
The list of and lists and or lists are used in logical judgments, and the following is the most common example:
[Condition] && command for true | | Command for false:
Executes commandfor true when the condition is true, and executes command for false when the condition is false
9,: Colon: Built-in null instruction, return value is 0 eg: $:
$ echo $?
$0
While: (the statement structure can implement an infinite loop)
10,; Semicolon: In the shell, the symbol that functions as "continuous instruction" is "semicolon" EG:CD ~/backup; mkdir startup; CP ~/.* startup/.
11, #: Indicates that the symbol is followed by the annotation text, will not be executed; * matches any character in the file name, including the string;
? Matches any single character in the file name.
~ Represents the user's home directory
12,/Inverted slash: placed before the command, there is the role of cancellation aliases (alias), before the special symbol, the role of the special symbol
At the very end of the instruction, indicating that the command joins the next line (which makes the carriage return invalid, and only acts as a line-feed)
14,! Exclamation point: Usually it represents the role of anti-logic, such as conditional detection, with! = to represent "not equal to" 15, * * Sub-square operation: two asterisks in the operation of the meaning of the "second party" Eg:let "Sus=2**3"
echo "SUS = $sus"
$ sus = 8

9, special characters of Linux

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.