调用自定义 shell 函数时生成文件尾随错误 "Command not found"
Makefile trailing error "Command not found" when calling custom shell function
我有一个简单的 Makefile:
define git_all
ls --recursive --directory --color=never */.git \
| sed 's/\/.git//' \
| xargs --no-run-if-empty --max-procs=10 --replace={} git -C '{}' || true
endef
gitpull:
@$(call git_all,pull -v)
'gitpull' 规则应该检测 Makefile 所在文件夹下的子文件夹中的所有存储库。例如:
Makefile
\- a/.git
\- b/.git
...
当我 运行 'make gitpull' 脚本工作正常,但有一个小故障。如果存储库已经是最新的,我会收到这个奇怪的尾随错误:
> make gitpull
make: Already: Command not found
make: *** [Makefile:xxx: gitpull] Error 127
我猜 shell 试图将文本 'Already up to date' 解释为命令,但它失败了。但为什么它首先要尝试这样做呢?我显然错过了什么,但是什么?
您似乎对 $(shell ...)
的作用感到困惑。如果您希望在目标为 运行 时发生这种情况,而不是在解析 Makefile 时发生,则需要取出 $(shell ...)
.
如果我能猜出你想做什么,可能是这样的
define git-all
find . -type d -name '.git' -execdir sh -c 'cd ..; git -C ' _ {} \;
endef
here:
$(call git-all,pull -v)
我有一个简单的 Makefile:
define git_all
ls --recursive --directory --color=never */.git \
| sed 's/\/.git//' \
| xargs --no-run-if-empty --max-procs=10 --replace={} git -C '{}' || true
endef
gitpull:
@$(call git_all,pull -v)
'gitpull' 规则应该检测 Makefile 所在文件夹下的子文件夹中的所有存储库。例如:
Makefile
\- a/.git
\- b/.git
...
当我 运行 'make gitpull' 脚本工作正常,但有一个小故障。如果存储库已经是最新的,我会收到这个奇怪的尾随错误:
> make gitpull
make: Already: Command not found
make: *** [Makefile:xxx: gitpull] Error 127
我猜 shell 试图将文本 'Already up to date' 解释为命令,但它失败了。但为什么它首先要尝试这样做呢?我显然错过了什么,但是什么?
您似乎对 $(shell ...)
的作用感到困惑。如果您希望在目标为 运行 时发生这种情况,而不是在解析 Makefile 时发生,则需要取出 $(shell ...)
.
如果我能猜出你想做什么,可能是这样的
define git-all
find . -type d -name '.git' -execdir sh -c 'cd ..; git -C ' _ {} \;
endef
here:
$(call git-all,pull -v)