make 中多行

发布于 2024-09-01 10:06:29 字数 449 浏览 3 评论 0原文

我试图在 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 正在将它们转换为空格。有什么建议吗?

I am trying to store a multiline string in a variable in 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}

This doesn't work, so I am wondering if this is possible at all. I need to preserve the newlines here and shell is converting them in spaces. Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唔猫 2024-09-08 10:06:29

这个怎么样:

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

How about this:

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}

or this:

.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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文