gpt4 book ai didi

makefile - 如何将文件内容分配给 Makefile 变量而不丢失回车符

转载 作者:行者123 更新时间:2023-12-04 21:17:31 29 4
gpt4 key购买 nike

根据 GNU manual :

It converts each newline or carriage-return / newline pair to a single space. It also removes the trailing (carriage-return and) newline, if it's the last thing in the result.



但是在没有回车的情况下使用 awk 会变得更加困难:
FILE = $(shell cat $(PATH))
TEXT = $(shell echo "$(FILE)" | awk '/Text/ {print $$3}')

所以我的问题是在将文件内容分配给 Makefile 变量时是否有办法保留回车符,或者任何智能解决方法?

最佳答案

不,您不能在 $(shell ...) 的结果中保留换行符功能。

您当然可以像这样更改您的 makefile:

FILE = $(PATH)
TEXT = $(shell cat $(FILE) | awk '/Text/ {print $$3}')

或者,为了避免 UUOC,
TEXT = $(shell awk '/Text/ {print $$3}' < $(FILE))

关于makefile - 如何将文件内容分配给 Makefile 变量而不丢失回车符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19450397/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com