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

标签 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

如何快速摆脱它?

最佳答案

您可以将文件名用双引号引起来

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/

关于bash - 如何转义 Makefile 中 cp 命令的括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27111040/

相关文章:

python - 在 bash 管道中使用时,保留 Jenkins 中 python 脚本的返回代码

linux - 显示所有 1 行 php 文件的 Shell 脚本

linux - 读取 shell 脚本中的行输出

makefile - 使用 Makefile 和 JSON 自动检索 MSK 详细信息

bash - docker-compose 卷 "no such file or directory"

makefile - 如何防止 'make clean' 构建计划删除的文件

c++ - 将对 Shell32.lib 的依赖添加到 WDK 生成文件

c - Makefile 每次构建目标

makefile - gnu-make:我应该引用ifeq语句的内容吗?

regex - 在带有 mv 的 bash 中使用正则表达式