这是一个 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/