[Makefile] The apices inside a file are lost

whired123

Member
Joined
Nov 15, 2021
Messages
151
Reaction score
10
Credits
1,097
Code:
$ tree
├── makefile
├── template
├── var1
└── var2

$ cat var1
xxx="true"

$ cat var2
yyy="false"

$ cat template
$config

$ cat makefile
var1 := $(shell cat var1)
var2 := $(shell cat var2)

default:
    sh -c "config='$(var1) $(var2)' envsubst < template"

$ make
sh -c "config='xxx="true" yyy="false"' envsubst < template"
xxx=true yyy=false

Observe the output last line

Code:
xxx=true yyy=false

But I expected

Code:
xxx="true" yyy="false"

Practically macan the apices.
Why?
 


the issue is with how the shell interprets the quotes in your makefile. When you use sh -c "config='$(var1) $(var2)' envsubst &lt; template", the shell strips the quotes around true and false.

Code:
var1 := $(shell cat var1 | sed 's/"/\\"/g')
var2 := $(shell cat var2 | sed 's/"/\\"/g')


default:
    sh -c "config='$(var1) $(var2)' envsubst < template"
 


Follow Linux.org

Staff online

Members online


Latest posts

Top