bash - Makefile bash & xargs 变量不起作用

标签 bash makefile

这是一个 Makefile

roman@debian ~/D/O/devops> cat Makefile 
install:
        -cat projects.txt  | xargs -n 2 bash -c 'git clone $0 $1'

这里是 projects.txt

roman@debian ~/D/O/devops> cat projects.txt
git@github.com:xxx/xxx1.git   app-xxx1
git@github.com:xxx/xxx2.git   app-xxx2

以下是我将此命令复制到 bash 时发生的情况 - 它有效:

roman@debian ~/D/O/devops> cat projects.txt  | xargs -n 2 bash -c 'git clone $0 $1'

fatal: destination path 'app-xxx1' already exists and is not an empty directory.

它正确地使用了 git clone 它只是 repo 存在。

现在当你执行 make install 时失败了,所有变量都是空白的:

roman@debian ~/D/O/devops> make install 
cat projects.txt  | xargs -n 2 bash -c 'git clone  '
You must specify a repository to clone.

我想在这里只使用 xargs 方法,否则它会变得太罗嗦,而且使用循环时会出现更多问题。我也尝试过使用 $(1) 但没有成功

最佳答案

make 将 $0$1 解释为 make 变量并尝试扩展它们。尝试将 $ 替换为 $$...

install:
        -cat projects.txt  | xargs -n 2 bash -c 'git clone $$0 $$1'

关于bash - Makefile bash & xargs 变量不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49053711/

相关文章:

linux - 调用多个 Bash 别名

bash - 在 sed 中扩展变量

bash - 找到: Arguments to -type should contain only one letter

linux - bash 使用特定分隔符分隔参数

Makefile - 将作业参数传递给子 makefile

c - 基础教程? Eclipse CDT 中的 Makefile

linux - Shell 脚本 - 如何根据输入模拟某些结果?

bash - 如何在不使用 "sh"或 "bash"命令的情况下运行 shell 脚本?

c - Linux 内核为 vmlinux 提供了 undefined reference ,但编译了 .o 文件

linux - 如何在 Makefile 中捕获退出 (ctrl+c) 信号?