Little Ant learns Linux (end)--linux pipe and definition variables

Source: Internet
Author: User
Tags learn php

1. Sequential execution of MULTIPLE commands

      ; semicolon splits each command

      Format: command 1; command 2. such as: LS;CD/.

Function: Multiple commands are executed sequentially, and there is no logical relationship between commands.

Note: The second command executes regardless of whether the first command is executed correctly.

&& Logic and

Format: Command 1 && command 2. such as: LS && CD ~

function: When command 1 is executed correctly, command 2 will not execute. When command 1 is executed incorrectly, command 2 does not execute.

|| Logical OR

Format: format: Command 1 | | command 2. such as: ls | | CD..

function: When command 1 is executed incorrectly, this command 2 executes. When command 1 is executed correctly, command 2 does not execute.

As an example: LS && echo yes | | Echo No when the first command executes, if executed correctly, then echo Yes, executed incorrectly, then echo No, is not a bit of the ternary operator feeling. But these two symbols can not be written upside down, otherwise it is wrong, remember. One of the reasons for enlightenment is to understand.


2. Pipe break

Command format: Command 1 | Command 2, not wrong, the middle is a small vertical line.

Function: The correct output of command 1 acts as an operand to command 2.

Note: With the pipe character, choosing the second command is very rigorous and requires manipulating the results from command 2.

Example: Netstat-an |    grep "established" | Wc-l two pipe-character nesting to view the current number of user connections


3. Wildcard characters

* Match multiple? Match a [] match any one of the atoms

Note: Wildcard characters can only match filenames and directories, and regular expressions are required to match data.

Refer to http://my.oschina.net/woshixiaomayi/blog/507939 for regular expressions


4. Linux definition variables

[Email protected] ~]# str=123

[[email protected] ~]# echo str

Str

Assign 123 to the variable str and the second sentence to the STR output.

The difference between single quotation marks and double quotes: single quotes will see the content as a string and will not parse the variables and special symbols. double quotes this resolves variables and special symbols in them.

The function of anti-quote:

such as: aa= ' ls ' system first executes LS, and then assigns the result of the execution command to AA. But the anti-quote, with our human eye is difficult to identify, easy to be seen as single quotes, so recommend this format instead of: $ (LS) its function and anti-quote is the same.

Escape character \ Function: The special symbol is escaped, for example: str=\ ' ls\ ' so that the anti-quote is lost, only as a string output.

Linux Foundation End Learn PHP's small ant original blog http://my.oschina.net/woshixiaomayi/blog



Little Ant learns Linux (end)--linux pipe and definition variables

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.