Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU Make: shell cat file yields contents without newlines

Makefile:

.PHONY: all
SHELL:=/usr/bin/env bash
all:
    $(eval x=$(shell cat file))
    @echo "$x"

File:

foo 
bar

Output:

foo bar

How do I get the contents of the file into the make variable without losing the newlines?

like image 602
Chris Avatar asked Dec 02 '25 09:12

Chris


1 Answers

You can't do this with shell, as described in its documentation.

If you have a sufficiently new version of GNU make, you can use the file function however.

like image 182
MadScientist Avatar answered Dec 05 '25 05:12

MadScientist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!