Shell Learning Classic

Source: Internet
Author: User
Tags alphabetic character character classes character set control characters numeric
Seven types of files

D Directory L Symbolic link

s socket file B block device file

C-character device file p named pipe file

-Regular file regular expressions

When you extract or filter text from a file or command output. Regular Expressions (RE) can be used, and regular expressions are a collection of special or not very special string patterns.

Basic meta-Character set:

^ matches only the beginning of the line.

$ matches only the end of the line.

* A single character immediately following *, matching 0 or more characters.

[] matches the characters in [], either as a single character or as a sequence of characters. Can make

Use-to denote a [] inner range, such as [1-5] equivalent to [1,2,3,4,5].

\ masks The special meaning of a meta-character, such as \$ represents the character $, and does not represent a matching row

Tail.

. matches any single character.

Pattern\{n\} matches the number of occurrences of pattern n

Pattern\{n,\}m matches the number of occurrences of pattern, but the minimum number of occurrences is n

Pattern\{n,m\} matches pattern occurrences between N and M (N,m is 0-255)

A few common examples:

Show executable files: ls–l | grep ... x...x. X

Show folders only: Ls–l | grep ^d

Match all blank lines: ^$

Match all the words: [A-Z a-z]*

Match any non-alphabetic character: [^a-z A-z]

Line with eight characters: ^........$ (8). Character class Description

The following is a fairly complete list of the available character classes:

[: Alnum:] alpha-numeric [A-Z 0-9]

[: Alpha:] letter [A-z]

[: Blank:] Space or TAB key

[: Cntrl:] any control character

[:d Igit:] number [0-9]

[: Graph:] Any visible character (no spaces)

[: Lower:] lowercase [A-z]

[:p rint:] Non-control characters

[:p UNCT:] punctuation character

[: Space:] Space

[: Upper:] uppercase [A-z]

[: xdigit:] hex digit [0-9 a-f a-f]

It is advantageous to use character classes as much as possible, as they can be better adapted to non-English locales (including some required accent characters, etc.). Shell's quotation mark type

There are four types of reference in the shell:

"" Double quotation marks

' Single quotation mark

' Anti-quote

\ Backslash

L "" can refer to any character or string other than $, ', \, or, and the variable in "" will display the value of the variable normally.

The difference between "and" "is that the shell ignores any reference value.

Example: Girl= ' GIRL '

echo "The ' $GIRL ' did well '

Then print: The ' girl ' did well

L ' is used to set the output of a system command to a variable, and the shell will use the contents of "as a system command and perform the quality."

For example, echo ' date ' prints the current system time.

L \ used to block special meanings of characters:& * + ^ $ ' "| ?

For example: Expr 12 \* 12 will output different modes when the 144 variable is set:

Valiable_name=value setting the actual value into Variable_name

Valiable_name+value if Variable_name is set, reset its value

Valiable_name:?value If Variable_name is not set, the undefined user error message is displayed first

Valiable_name?value If Variable_name is not set, a system error message is displayed

Valiable_name:=value If Variable_name is not set, its value is set

Valiable_name-value, but the value is not set to the variable_name condition test

The test command is used for testing strings, file states, and numbers, and expr tests and executes numeric outputs.

Test format: Test condition or [condition] (it is important to note that there is a space on both sides of the condition, otherwise it will be an error), the test command returns 0 to indicate success.

The three tests of test are described below, respectively:

N File status test (Common)

-D test whether the folder

-F Tests whether generic files

-l test whether to link files

-R test File is readable

-W test file is writable

-X test whether the file is executable

-S test file is not empty

N String Test

Five formats: Test "string"

Test String_operator "String"

Test "string" String_operator "string"

[String_operator "string"]

["String" String_operator "string"]

Where string_operator can be: = two strings are equal

! = Two String unequal

-Z Empty string

-N Non-empty string

N Numerical Test

Two formats: "Number" Number_operator "number"

["Number" number_operator "number"]

Where: Number_operator can be:-eq,-ne,-gt,-lt,-ge

Example: number=130

["990" le "995" –a "number"-GT "133"]

(Where-a means "and" before and after results)

The L expr command is generally used for integer values, but can also be used for strings.

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.