Dup Ver Goto 📝

BashExtendedGlobs

PT2/aw/os/shell does not exist
To
22 lines, 112 words, 735 chars Page 'BashExtendedGlobs' does not exist.

To enable:

shopt -s extglob

Basics

?(pattern-list)   # Matches zero or one occurrence of the given patterns.
*(pattern-list)   # Matches zero or more occurrences of the given patterns.
+(pattern-list)   # Matches one or more occurrences of the given patterns.
@(pattern-list)   # Matches one of the given patterns.
!(pattern-list)   # Matches anything except one of the given patterns.

Examples

!(*.c|*.h)        # matches all files _except_ .c and .h files
@(*.jpg|*.gif|*.png) # matches some image files

Caveats

You cannot switch extglob on inside a function -- it must be enabled before the function body is parsed. You can, however, switch it off inside a function.