1

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Navi
  • 8,580
  • 4
  • 34
  • 32
  • Any reason you can't have the text you need to use in an external file vs. inside the makefile? – AlG May 13 '10 at 15:13
  • Does this answer your question? [Is it possible to create a multi-line string variable in a Makefile](https://stackoverflow.com/questions/649246/is-it-possible-to-create-a-multi-line-string-variable-in-a-makefile) – Zoe Jun 26 '20 at 17:33

1 Answers1

-1

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
Beta
  • 96,650
  • 16
  • 149
  • 150