A concise summary of the role of 28 special characters in a shell script _linux shell

Source: Internet
Author: User

1. #

annotation function, #! Except
In addition, in the parameter replacement echo ${path#*:} here does not represent a comment, a numbering conversion, does not represent a comment echo $ ((2#101011))

2.;

Command line separator, you can write multiple commands on one line. echo Hello; echo there

3.;;

Terminate case option

Copy Code code as follows:

Case "$variable" in
ABC) echo "\ $variable = abc";;
XYZ) echo "\ $variable = xyz";;
Esac


4..
Hide file Prefix
. command is equivalent to source
. Represents the current directory ... Indicates a previous level of directory
Match as a single character in a regular expression

5. "", "

Double quotes, single quotes, where you can reference variables in double quotes, but not in single quotes, which function as organization special characters

6. \

Escape character

7./

File name Separator, Division action

8. ' (ESC button below)

Post reference, command substitution

9.:

Null command, equivalent to "NOP"
can also be considered to be the same as the Shell built-in command true, for example: Dead loop

Copy Code code as follows:

While:
Todo
echo "1"
Done

Equivalent to:
Copy Code code as follows:

While True
Todo
echo "1"
Done

To make a placeholder in a if/then statement:
Copy Code code as follows:

If condition

Then: # do nothing, draw branches

Else

Do other thing

Fi

Provides a placeholder in a 2-dollar command.

When used with the > (redirection operator), empty the file without modifying the file's permissions, such as: (if the file does not exist, the file will be created)

: > Data.log equivalent to

Cat/dev/null > Data.log


10.!

The inverse operator!= is not equal to

11. *

Universal matching character, in regular expressions
Math multiplication
* * Power operation

12.?

Test actions
Regular expression,? Match any single character

13. $

Variable symbol
Regular expression row end character
${} parameter substitution
$*,$@ Position Parameters
$? Exit status
$$ Process ID

14. ()

Command group, (A=hello Echo $a), and the list of commands in () will run as a child shell. The variables in (), because they are in the child shell, are not available for the remainder of the script.
Array initialization: array= (element1, Element2, Element3)

{XXX,YYY,ZZZ}

Curly braces Extension
Cat {File1,file2,file3} > Combined_file, merge file1,file2,file3 together and redirect to Commbined_file. Cannot have spaces in curly braces

16. {}

code block. In fact, this structure creates an anonymous function. But unlike a function, the variable declared in it is visible to the code for the rest of the script.

Copy Code code as follows:
# The content in the code block, external access, I/O redirection

1: #!/bin/bash
2:
3:file=/etc/fstab
4:
5: # in this block of code variables, external can also access
6: {
7:read line1
8:read line2
9:} < $File
10:
11:echo "The" the "a" in $File is "
12:echo "$line 1"
13:echo
14:echo "Second line in $File is"
15:echo "$line 2"
16:
17:exit 0
# Save the results of a code block to a file


17. {}\;

Path names, are generally used in the Find command, attention; –exec to end the find command sequence

18. []

Test

Array elements, such as ARRAY[1]=ABC
The range of characters used in regular expressions

19. [[]]

The test expression itself is placed in []

20. (())

Mathematical calculation extension

>& >>& >> <

redirect
ScriptName > FileName redirect script output to file, overwrite original content
Command &> filename redirect stdout and stderr to file
Command >&2 redirect stdout and stderr
ScriptName >> filename Redirection scripts are exported to the file, added to the end of the file, and if there are no files, create the file.

<< <<<

Redirect, << used in "Here Document", <<< used in "here string"


\<, \>

Word boundaries in regular expressions grep ' \<the\> ' testfile

24. |

Pipe, analyze the output of the front command, and use the output as input to the following command


>|

Force redirection

26. | |

Logical OR

&

Run the command in the background, a command followed by an ampersand, will indicate running in the background

Copy Code code as follows:

1: #!/bin/bash
2:
3:for I in 1 2 3 4 5 6 7 8 9 10
4:do
5:echo-n "$i"
6:done&

Note that the last done& of the For loop

&&

Logic and

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.