tags:

views:

32

answers:

2

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?

A: 

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
+2  A: 

Asked and answered here: Is it possible to create a mult-line string variable in a makefile?.

Eric Melski
It works also on Mac OS X. Small correction in the answer @echo "$$ANNOUNCE_BODY"so that's double NN.
Navi