Shell and regular expressions

Source: Internet
Author: User

Shell expression


Whether the-D file exists and is a directory

The-f file is present and is a normal file

Whether the-W file file exists and is writable

-s file exists and is not empty

-N string string length not 0

String1=string2 string Equality

-eq equals

-GT Greater than

-lt less than

Whether the-e file exists

-R file exists and is readable

The-x file file exists and is executable

Whether the-h file is a linked file

-Z String string length is 0

String1!=string2 String Range

-ge greater than or equal to

-le less than or equal to

-ne Not equal to


Single quotation marks

Echo ' $HOME '

$HOME


echo "$HOME"

/root


echo "\ $HOME"

Escape


echo "ABC ' Date +%d '"

ABC 12/07/16


echo "ABC $ (date +%d)"

ABC 12/07/16


Regular expressions

. Match any single character

* Match previous character appears 0 or more times

. * Match any number of arbitrary strings

[] matches any single character in the collection

[x-y] matches a contiguous range of strings

^ Match string start

$ Match String End

[^] Match negation, reverse the set in parentheses

\ matches the escaped string

\{n,m\} matches the previous character repeats N to M times

\{n,\} matches the previous character at least n times

\{n\} matches the previous string repeated n times

\ (\) stores the contents between \ (and \) in "Reserved Space" with a maximum of 9 storage

\ NAND \1 to \9 to call the contents of the reserved space

{n,m} is equivalent to \{n,m\}

+ matches one or more occurrences of the previous character

? Matches the previous character one or 0 times

| Logical OR, match before or after string

() match a regular set



eg
Grep:.. 0:passwd

grep 00* passwd

grep o[oa]t passwd

grep [0-9] passwd

grep ^root passwd

grep bash$ passwd

grep Sbin/[^t] passwd

grep ' 0\{1,2\} ' passwd

grep "\ (root\) \ (: \). *\2\1" passwd

grep ^$ passwd

Grep-v ^$ passwd




This article is from the Linux Learning Notes blog, so be sure to keep this source http://rockycai.blog.51cto.com/8871643/1881674

Shell and regular expressions

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.