According to 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.
But it makes more difficult to use awk without carriage-returns:
FILE = $(shell cat $(PATH))
TEXT = $(shell echo "$(FILE)" | awk '/Text/ {print $$3}')
So my question is whether there is a way to keep carriage-returns when assign a file content to a Makefile variable, or any smart workarounds?
No, you cannot preserve newlines in the results of the $(shell ...)
function.
You can of course change your makefile like this:
FILE = $(PATH)
TEXT = $(shell cat $(FILE) | awk '/Text/ {print $$3}')
Or, to avoid UUOC,
TEXT = $(shell awk '/Text/ {print $$3}' < $(FILE))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With