nowox
nowox

Reputation: 29106

How to escape parenthesis for the cp command inside a Makefile

I have this Makefile:

VAR=foo(1).txt foo(2).txt
foobar: $VAR
    cp -p $^ foo/    

When I run it I get this error:

$ make test
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `cp -p foo(1).txt foo(2).txt foo/'
Makefile:3: recipe for target 'foobar' failed
make: *** [test] Error 1

How to quickly get rid of it?

Upvotes: 2

Views: 1611

Answers (1)

nu11p01n73R
nu11p01n73R

Reputation: 26667

You can wrapt the file names in double quotes

cp "foo(1).txt" "foo(2).txt" /out

Test

$ cp "foo(1).txt" "foo(2).txt" out/
$ ls out/
foo(1).txt  foo(2).txt

Or much safer would be

cp 'foo(1).txt' 'foo(2).txt' out/

Upvotes: 2

Related Questions