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