Makefile中的多行bash命令 [英] Multi-line bash commands in makefile

查看:73
本文介绍了Makefile中的多行bash命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑到每个命令都在自己的shell中运行,在makefile中运行多行bash命令的最佳方法是什么?例如,像这样:

Considering that every command is run in its own shell, what is the best way to run a multi-line bash command in a makefile? For example, like this:

for i in `find`
do
    all="$all $i"
done
gcc $all

推荐答案

您可以将反斜杠用于行继续.但是请注意,shell接收到整个命令,并将其合并为一行,因此您还需要用分号终止某些行:

You can use backslash for line continuation. However note that the shell receives the whole command concatenated into a single line, so you also need to terminate some of the lines with a semicolon:

foo:
    for i in `find`;     \
    do                   \
        all="$$all $$i"; \
    done;                \
    gcc $$all

但是,如果您只想获取 find 调用返回的整个列表并将其传递给 gcc ,则实际上不一定需要多行命令:

But if you just want to take the whole list returned by the find invocation and pass it to gcc, you actually don't necessarily need a multiline command:

foo:
    gcc `find`

或者,使用更常规的shell传统的 $(command)方法(请注意,虽然 $ 会转义):

Or, using a more shell-conventional $(command) approach (notice the $ escaping though):

foo:
    gcc $$(find)

这篇关于Makefile中的多行bash命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆