-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash.globs.rme
More file actions
56 lines (46 loc) · 2.62 KB
/
bash.globs.rme
File metadata and controls
56 lines (46 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#2018#02#16 #bash#expansion#pathname #sh #gnu #globs #wildcards
=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=
| Pathname Expansion a.k.a. Globbing |
=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=
"Glob" refers to a set of Bash features regarding pattern matching or
expanding patterns. Bash interprets globs on unquoted command-line args.
Synonyms include "pattern matching", "pattern expansion",
"filename expansion", "wildcards", etc.
Traditional Glob/Wildcard Special Characters:
* matches 0 or more characters
? matches precisely 1 character
[...] matches a range
! negates a match in a range ('\' escaping unnecessary)
^ negates a match in a range (synonym for '!')
\ traditional escape character
~~> char after loses special meaning.
Ranges allow globs to match a set of characters. For example:
[abcd] matches 'a' or 'b' or 'c' or 'd'
[a-d] the same as above
[^a-d] matches any character _except_ 'a' - 'd'
[0-9a-zA-Z] matches every single alphanumeric ASCII character
[-...] to match a literal '-', put it first or last
[...-] the same as above
[...^...] to match a literal '^', put it anywhere except the start
[]...] to match a literal ']', put it first
[^]...] same as above but with negation
(all instances of '^' can be substituted with '!')
Extended Globs
to enable extended globs, run the following command:
$ shopt -s extglob
Extended Shell Globs:
?(pattern-list) matches 0 or 1 occurence of pattern-list
*(pattern-list) matches 0 or more occurrences of pattern-list
+(pattern-list) matches 1 or more occurrences of pattern-list
@(pattern-list) matches exactly 1 occurrence of pattern-list
!(pattern-list) matches anything except 1 occurrence of pattern-list
pattern-list: a list of items separated by a '|'
Regular Expression equivalents:
?(pattern-list) (...|...)?
*(pattern-list) (...|...)*
+(pattern-list) (...|...)+
@(pattern-list) (...|...) ['@' is not RE syntax]
!(pattern-list) Use '^' for negations or negative lookahead
=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=
| ~ finis ~ |
=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=~+~=