如何在Makefile中转义cp命令的括号

时间:2014-11-24 17:49:28

标签: bash makefile

我有这个Makefile:

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

当我运行它时,我收到此错误:

$ 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

如何快速摆脱它?

1 个答案:

答案 0 :(得分:1)

您可以用双引号

包装文件名
cp "foo(1).txt" "foo(2).txt" /out

<强>测试

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

或者更安全

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