Search code examples
shellunix

Why does foo{bar, baz} not expand to "foobar" and "foobaz"?


I have two files in my directory:

com.my.arsys.core.js
com.my.arsys.core-libs.js

Now I want to match these using globbing pattern (curly braces) and copy them to a folder so I run the following:

cp com.my.arsys.{core, core-libs}.js a

However I get the following errors:

cp: cannot stat 'core,': No such file or directory
cp: cannot stat 'core-libs,': No such file or directory

I think the problem is with the syntax. What can I try next?


Solution

  • You have an extra blank, try:

    cp com.my.arsys.{core,core-libs}.js a
    

    From bash man about Brace Expansion:

    A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression. Any incorrectly formed brace expansion is left unchanged.