Pro Backup
Pro Backup

Reputation: 761

Why does (*.foo|bar) cause an error, but !(*.foo|bar) does not?

Error

line 852: syntax error near unexpected token `('

Line 852 is the last line of a function:

touch --reference="$KERNEL_FILE" "$moduledest"/modules.(*.bin|devname|softdep)

No error

When inserting the exclamation mark ! before (:

touch --reference="$KERNEL_FILE" "$moduledest"/modules.!(*.bin|devname|softdep)

How to touch the inverse of !(*.bin|devname|softdep)?

/modules.alias.bin
/modules.builtin.bin
/modules.dep.bin
/modules.devname
/modules.softdep
/modules.symbols.bin

Upvotes: 3

Views: 86

Answers (1)

Pro Backup
Pro Backup

Reputation: 761

Extended glob

The pattern you are trying to negate match with the exclamation mark is an "extended glob". Enabled somewhere in the script with a command alike shopt -s extglob.

The negation form with extended globbing syntax is defined as !(list):

!(list) Matches anything but the given patterns.

The inverse of that negative match in this case is the syntaxis @(list):

@(list) Matches one of the given patterns

Upvotes: 3

Related Questions