【问题标题】:Multiple lines in make [duplicate]make中的多行[重复]
【发布时间】:2010-05-13 15:01:13
【问题描述】:

我正在尝试将多行字符串存储在 make 中的变量中

var=$(shell cat <<End-of-message \
-------------------------------------\
This is line 1 of the message.\
This is line 2 of the message.\
This is line 3 of the message.\
This is line 4 of the message.\
This is the last line of the message.\
-------------------------------------\
End-of-message)


printit:
    @echo ${var}

这不起作用,所以我想知道这是否可能。我需要在此处保留换行符,并且 shell 将它们转换为空格。有什么建议吗?

【问题讨论】:

标签: makefile


【解决方案1】:

这个怎么样:

define var
@echo -------------------------------------
@echo This is line 1 of the message.
@echo This is line 2 of the message.
@echo This is line 3 of the message.
@echo This is line 4 of the message.
@echo This is the last line of the message.
@echo -------------------------------------
endef

printit:
    ${var}

或者这个:

.PHONY: var
var:
    @echo -------------------------------------
    @echo This is line 1 of the message.
    @echo This is line 2 of the message.
    @echo This is line 3 of the message.
    @echo This is line 4 of the message.
    @echo This is the last line of the message.
    @echo -------------------------------------

printit: var

【讨论】:

    猜你喜欢
    • 2011-10-28
    • 2011-09-11
    • 1970-01-01
    • 2011-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-28
    • 1970-01-01
    相关资源
    最近更新 更多