Linux Special symbols
===========================================================================================
$ number
Usually represents the meaning of a variable
echo $ variable name = variable Value
= equals sign
The general definition of variables is used when
For example [[email protected] aaa]# ABC=/ETC/PASSWD
[Email protected] aaa]# echo $ABC
/etc/passwd
^
This symbol represents the "start" position of a row in a regular expression
For example [[email protected] aaa]# grep "^a" 111
ACBac0AAA
ABCWWDwww
# Number of Wells
1. Often the beginning of a line of shell script, or as a comment information, such a case that the symbol is followed by the text, will not be executed.
For example: # This is comments.
2, or to comment out the command, do not let this command execute
For example: #echo "www.baidu.com" >/root/abc
; semicolon
Command 1; Command 2: Indicates whether the preceding command executes successfully, executes the following command, which is equivalent to carriage return, and can execute multiple commands
For example: [[email protected]/]# cd/root/; ls-l
Total 84
-rw-r--r--1 root root 4 09-29 14:55 1.txt
;; Double semicolon
Dedicated in case options, assume the role of Terminator. Don't do too much explaining
&
Indicates job control, the foreground command is transferred to the background
&& symbols, logic and
Command 1 && Command 2: Command 1 on the left executes successfully and command 2 on the right is executed. If command 1 on the left does not execute successfully, command 2 on the right does not execute
For example:
[Email protected] ~]# echo "abc" >>/root/1.txt && ls-l/root/1.txt
-rw-r--r--1 root root 4 09-29 14:55/root/1.txt
If there is no 1.txt file in the directory, the command is automatically created and then added ABC to 1.txt.
| Pipeline
Command 1 | Command 2: Output of the preceding command, as input to the following command
For example: [[email protected]/]# cat/etc/passwd |wc-l
38
|| Dual pipe, logic or
Command 1 | | Command 2: Command 1 on the left executes successfully, and command 2 on the right does not execute. If command 1 on the left does not succeed, command 2 on the right does not execute
For example:
[[email protected] ~]# Ls-l Www.txt | | Touch Www.txt
Ls:www.txt: No file or directory
For example: [[email protected] ~]# Ls-l Www.txt | | echo "Yes"
-rw-r--r--1 root root 0 09-29 15:03 www.txt
' Single quotation mark
The contents of single quotes are treated as ordinary symbols, preventing any variable substitution
Example:$www =www.baidu.com
[Email protected] ~]# echo "$www"
Www.baidu.com
[Email protected] ~]# echo ' $www '
$www
"" Double quotation marks
The content enclosed in double quotes is treated as a single string, preventing wildcard expansion, but allowing variable expansion.
Example:$www =www.baidu.com
[Email protected] ~]# echo "$www"
Www.baidu.com
For example: echo "\"/root/www/"\"
"/root/www/"
"\\": Backslash converts special characters
"\"//"\" backslash
Convert Special Symbols
For example: echo "\"/root/www/"\"
"/root/www/"
"Anti-apostrophe, inverted quote = = $ ()
' Command ': The counter-apostrophe is the command to execute
For example 1, [[email protected] ~]# fdv= ' date +%f '; echo "Today $FDV"
Today 2014-09-29
Example 2, [email protected]/]# fdv=$ (date +%f); echo "Today $FDV"
Today 2014-09-29
* No.
Match any symbol of any length
Example:ls/root/*.txt
1.txt Aaa.txt Www.txt
* * No.
Represents a sub-square operation
For example: [[email protected] ~]# let b=4**2; Echo $b
16
? Question mark
Match individual length of a single character
For example: [[email protected] ~]# ls/root/?. Txt
/root/1.txt
Comma
This symbol is often used in operations as an "isolated" use.
。 Period
Indicates a hidden file or current directory, no big use, no more explanation
: Colon
Usually in the script to do the interval effect
! Exclamation mark
The meaning of "non" in the sense of logical operation, mainly used in awk
_ Short horizontal bar, commonly known as minus
is usually the CD command inside the back to the last working directory meaning
Or as an arithmetic symbol
~ Wave number
Generally used for CD commands
[] Brackets
[[email protected] aaa]# ls
A d f FH h R
[ABCD] There must be a character or a or B or ... is one of the characters in parentheses that matches the display
[Email protected] aaa]# ls-l [ABCD]
-rw-r--r--1 root root 0 10-02 19:49 a
-rw-r--r--1 root root 0 10-02 19:49 D
Represents a continuous combination of
[email protected] aaa]# ll *[0-9]*
-rw-r--r--1 root root 0 10-02 19:18 1
-rw-r--r--1 root root 5 10-02 19:18 111
-rw-r--r--1 root root 0 10-02 19:18 2
-rw-r--r--1 root root 0 10-02 19:28 w323ewq
[-]
Represents a continuous match from-before-to-after, if no continuation matches are not displayed next until consecutive characters end, and then the matching values are displayed
For example
[[email protected] aaa]# ll [1-3] represents all numbers between 1-3
-rw-r--r--1 root root 0 10-02 19:18 1
-rw-r--r--1 root root 0 10-02 19:19 3
[^]
To denote the meaning of inversion
[[email protected] aaa]# ll [^1-5] match all numbers except 1 to 5
-rw-r--r--1 root root 0 10-02 19:19 6
-rw-r--r--1 root root 0 10-02 19:19 7
-rw-r--r--1 root root 0 10-02 19:19 8
-rw-r--r--1 root root 0 10-02 19:19 9
() parentheses
Typically represents the beginning of a neutron shell in a shell statement
[[email protected] aaa]# awk ' {if ($0~/abc/) print $ ' 111
Abc
{} curly Braces
Middle is a combination of command blocks
Example 1,
Cat 111 |awk ' {print $} '
Example 2,
Represents a collection
[[email protected] aaa]# Touch {1..9}{a,b,c}
[[email protected] aaa]# ls
1a 1b 1c 2a 2b 2c 3a 3b 3c 4a 4b 4c 5a 5b 5c 6a 6b 6c 7a 7b 7c 8a 8b 8c 9a 9b 9c
/Slash: 1, meaning of the path to the directory + addition operator-subtraction operator \* multiplication operator /division operator % fetch operator
Example: Echo "/etc/passwd/"
/etc/passwd
For example: [[email protected] ~]# x=100
[Email protected] ~]# a=30
[Email protected] ~]# expr $x + $a
130
[Email protected] ~]# expr $x-$a
70
[Email protected] ~]# expr $x \* $a
3000
[Email protected] ~]# expr $x/$a
3
[Email protected] ~]# expr $x% $a
10
File descriptor name common abbreviation default value
0 Standard Input stdin keyboard
1 Standard output stdout screen
2 standard error Output stderr screen
When we simply use < or >, the equivalent of using 0< or 1>
1> indicates the correct output
0> indicates the correct output
> Add the output to a text file and overwrite the original
>> Appends the output content results to a text file without overwriting the original
>test.txt If you have test.txt this file, clear all the contents of the file
If you do not have a test.txt file, create a Test.txt file
< Data flow redirection: Save content in a file beforehand, specify the file path when needed, and the system can automatically detect the read
<< Input Guidance
&> or 2>&1 add the correct output and error information to the same text file and overwrite the original
&>> Add the correct information of the output to the same text file as the error message, and append it in
2> adds the output error message to the text file and overwrites the original
2>> Appends the output error message to a text file, and does not overwrite the original
echo "www" >1.txt 2>2.txt means that the correct information is entered into a 1.txt file, and the wrong information is entered into a 2.txt file
Saving the wrong information can be 2>/dev/null
Cat > www
Www.baidu.com
Www.taobao.com
Press Ctrl+d to exit
Then the information you entered will be stored in the WWW file.
Cat > www << "EOF"
Www.baidu.com
Www.taobao.com
EOF does not need to press Ctrl+d to exit
It's over now.
$# indicates the number of positional parameters in the command line
Cases:
[Email protected] ~]# vim test.sh
#!/bin/bash
#
echo "The current position variable is: $ $"
echo "The current position variable is: $"
echo "The current position variable is: $ $"
echo "The current position variable is: $4"
Echo $#
[Email protected] ~]#/test.sh a b c D
The current position variable is: a
The current position variable is: b
The current position variable is: C
The current position variable is: D
4 Statistics out the use of several positional variable parameters
$* represents the contents of all positional parameters
Cases:
[Email protected] ~]# vim test.sh
#!/bin/bash
#
echo "The current position variable is: $ $"
echo "The current position variable is: $"
echo "The current position variable is: $ $"
echo "The current position variable is: $4"
Echo $*
[Email protected] ~]#/test.sh a b c D
The current position variable is: a
The current position variable is: b
The current position variable is: C
The current position variable is: D
A b c D shows the contents of the position variable (value)
$? represents the return status of the previous command after execution, with a return value of 0 indicating that the execution is correct, and that a value other than 0 is an execution error
Example 1,
[[email protected]/]# ls www
Ls:www: No file or directory
[[email protected]/]# echo $?
2
For example: [[email protected] ~]# CAT/ETC/PASSWD
[[email protected] ~]# echo $?
0 Returns a value of 0, indicating that the command executed earlier CAT/ETC/PASSWD is correct
$ A indicates the name of the currently executing script or program
Cases:
[Email protected] ~]# vim test.sh
#!/bin/bash
#
echo "The current position variable is: $ $"
echo "The current position variable is: $"
echo "The current position variable is: $ $"
echo "The current position variable is: $4"
Echo
[Email protected] ~]#/test.sh a b c D
The current position variable is: a
The current position variable is: b
The current position variable is: C
The current position variable is: D
./test.sh Show executed scripts or programs
This article symbol is sufficient in simple or normal scripts, and there are special symbols that involve certain commands, which I'll add to the specific commands.
All right! Now probably know so many symbols, perhaps some special symbols I have not learned, if there are shortcomings in the hope that you have a lot of readers forgive, learn from each other.
Thank you for your support!
This article is from the "LINUXCBB" blog, make sure to keep this source http://linuxcbb.blog.51cto.com/9434555/1560411
Use of special symbols for Linux