[Shell] bash basic functions: Multi-command sequential execution and pipeline operators

Source: Internet
Author: User

/* Configure /*-----------------------------------------------------------------------------------------------

@ Blackeye poet <www. chenwei. ws>

Optional -----------------------------------------------------------------------------------------------*/

1. Multiple commands are executed sequentially.

Semicolon (;)

Logic and (&&)

Logic or (|)

 

Semicolon:

Ls;Date;CD/user;PWD

Execution sequence: commands are executed sequentially. There is no relation between commands and they do not affect each other.

Purpose: connect multiple commands to simplify operations

 

Example:

Dd If = input file of = output file BS = Bytes Count = count (used to copy a disk)

(Date; dd If =/dev/Zero of =/home/testfile BS = 1 k count = 10000; Date) # Count the execution time

Option:

If = input file specifies source file or Source Device

Of = specifies the target file or target device for the output device.

BS = the number of bytes specifies the number of bytes input/output at a time, that is, these bytes are considered as a data block.

Count = number of data blocks specified for Input/Output

 

Logic and:

  Ls & Echo Yes

Execution sequence: The second command is executed only when the first command is successfully executed.

Purpose: The command has a logical relationship and must have a certain execution order.

 

Logic or:

  Ls | echo No

Execution sequence: the first is successfully executed, the second is not executed; the first is not executed correctly, and the second is executed

Purpose: Determine whether the previous command is correctly executed

 

Use of logic and logic or combination:

  Command & Echo Yes | echo No# Use this method to determine whether the command is executed

 

2. pipeline operator:

  Command 1 | command 2# Use the result of command 1 as the operation object of command 2

Example:

Ls-L | more # display the correct command execution result on multiple screens

  

  Grep [Option] 'search content' file name# Search for matching strings in the file

Option:

-I case-insensitive

-N: Output row number

-V reverse lookup

-- Color = the keywords searched by auto are displayed in color.

(View the number of remote connections on the current computer)

 

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.