blob: bc7534c26e223240110b067fddcf360d638e7b66 (
plain)
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
|
---
tags:
- linux
---
[[Bash]]
---
https://linux.die.net/man/7/glob
**Wildcards**
- \*: any str, including empty
- ?: any single char
**Character classes** are wrapped with []. First char can't be ! and it can't be empty. Thus to match [ ] and ! we need to wrap them like so `[][!]`
**Ranges** two chars separated by `-`.
**Complementation** `[!..]` match any chars not in the character class.
**Pathnames** globbing applies to component seperately. `/` not allowed in character classes. Wildcards don't match `/`.
Dot files must be explicitly matched, thus `*` will not match it.
**Empty lists** A wildcard can expand into an empty list (e.g `*.gif` where no .gif exist). If the wildcard expands to an empty list or is invalid it will remain unchanged per POSIX specifications.
In bash `shopt -s nullglob` enables expanding into an empty list.
### Difference with Regular Expressions
With globbing we match filenames rather than text.
|