branquito
branquito

Reputation: 4044

Copy files using globbing (where no match), zsh

In zsh on a command line I can get this to work as desired:

cp some_dir/!(0*).jpg dest_dir/

and it will copy over all files which do not begin with 0 to dest_dir.

But when I try to use the same from a zsh script, I get the following error:

no matches found: some_dir/!(0*).jpg

What's the problem here, and how to resolve it?

Upvotes: 0

Views: 429

Answers (1)

Adaephon
Adaephon

Reputation: 18349

This feature requires the shell option KSH_GLOB to be set:

setopt kshglob

See the ZSH Manual on ksh-like Glob Operators for more information.


Alternatively, one can set the option EXTENDED_GLOB and use ^ to negate (partial) patterns:

setopt extendedglob
cp some_dir/(^0*).jpg dest_dir/

Upvotes: 1

Related Questions