9

If I have two files (in a folder with similarly numbered files) such as

foo.18
foo.19

And I want to use a glob on them, do I do it like so:

cp -r /folder1/*.{19,20} /folder2/

or like so?

cp -r /folder1/{*.19,*.20} /folder2/

Neither seem to expand out when I tap tab.

Is one 'better than the other? What order does it expand in? Will it ever matter?

AncientSwordRage
  • 1,714
  • 1
  • 20
  • 26

1 Answers1

12

No, it doesn't matter. bash expands the glob after expanding the braces, so either will work.

$ tee foo bar baz </dev/null
$ echo *{a,o}*
bar baz foo
$ echo {*a*,*o*} 
bar baz foo
$ echo {*,*}
bar baz foo bar baz foo
Chris Down
  • 122,090
  • 24
  • 265
  • 262
  • And if you do want to do globbing here instead of expanding several globs after brace expansion, you can use `ksh` extended globbing with `echo *.@(19|29)` (enabled in `bash` with `shopt -s extglob`). – Stéphane Chazelas Jul 19 '13 at 10:11