makefile - Safely pass Make variable to shell commands -


consider makefile:

var1=oneword var2=two words var3=three" quoted "words  test:     printf '>%s< ' "$(var1)" "$(var2)" "$(var3)"     @echo 

if run it, get

$ make test printf '>%s< ' "oneword" "two words" "three" quoted "words" >oneword< >two words< >three< >quoted< >words< print 

but same result if ran following command:

$ printf '>%s< ' "oneword" "two words" "three\" quoted \"words" >oneword< >two words< >three" quoted "words< 

assume cannot change variables, i.e. have change call printf somehow.

in other words: how pass content of make variable shell command 1 parameter, without splitting several or specific shell effects occurring?

make supports export directive pass literal content through environment:

var1=oneword var2=two words var3=three" quoted "words  export var1 export var2 export var3  test:         printf '>%s< ' "$$var1" "$$var2" "$$var3"         echo 

output:

$ make test printf '>%s< ' "$var1" "$var2" "$var3" >oneword< >two words< >three" quoted "words< echo