Linux-shell-|, & {}, (), reg-command execution sequence

Source: Internet
Author: User

Linux-shell-|, & {}, (), reg-command execution sequence

 

&&
Format: command 1 & command 2
Purpose: & after the command on the left (command 1) returns true (that is, 0 is returned, successfully executed), the command on the right (command 2) can be executed.
Example:
$ MV/apps/bin/apps/dev/bin & Rm-r/apps/bin
Note: The/apps/bin directory will be moved to the/apps/dev/bin directory. If it is not successfully executed, the/apps/bin directory will not be deleted.

|
Format: command 1 | command 2
Purpose: if | the command on the left (command 1) is not executed successfully, execute | the command on the right (command 2)
For example, if the script is not successfully executed, the s h e l will end.
$ Comet month_end.txt | exit

Use () and {} to combine commands
How to execute multiple commands together:
1) execute a group of commands in the current shell. Each command can be separated by a command separator and all commands are enclosed in parentheses.
Format:
(Command 1; command 2 ;...)

2) subshell execution, replace () {}
Format: {command 1; command 2 ;...}

Note: Only when the output of all commands in {} is redirected as a whole, the commands are put into the sub-shell for execution. Otherwise, the commands are executed in the current S H E L

Comprehensive
These commands are used in combination.
Example:
$ Comet month_end | (echo "Hello, comet did not work" | mail myself; Exit)
If the script fails to be executed, first send an email to yourself and then exit.

(),{}

(Cmd1; cmd2;...; cmdn) # execute a group of commands in a sub-shell
{Cmd1; cmd2;...; cmdn} # execute a group of commands in the Current Shell

Regular Expression

^ Match only the beginning of a row
$ Only matches the end of a row
* Only one single character followed by *, matching 0 or more single characters
[] Only matches the characters in. It can be a single character or a character sequence. You can use-to represent the range of character sequences in []. For example, use [1-5] instead of [1 2 3 4 5].
\ Is used only to block the special meaning of a metacharacter. Because sometimes some metacharacters in s h e l have special meanings. \ Can make it meaningless
. Only match any single character
Pattern \ {n \} is only used to match the occurrence times of the previous pattern. N is the number of times
Pattern \ {n, \} m only indicates the same as above, but the minimum number of times is n
Pattern \ {n, m \} only indicates the same as above, but the occurrence frequency of pattern is between N and M.

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.