Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GNU make equivalent to BSD make's $(var:Q)?

BSD make has a :Q variable expansion modifier, documented in the FreeBSD make man page as follows:

:Q   Quotes every shell meta-character in the variable, so that it can be
     passed safely through recursive invocations of make.

If variable var has value a b\c"d'e$f, then $(var:Q) expands to a\ b\\c\"d\'e\$f (or something equivalent). This is useful to pass strings to the shell without worrying that the shell will interpret any special characters.

Does GNU make have an equivalent? Or do I have to escape special characters my own?

like image 227
Richard Hansen Avatar asked Oct 23 '25 08:10

Richard Hansen


1 Answers

GNU make provides functions subst and patsubst which can help solve the problem. Those are more general, but require more work by the developer since they do not solve the specific problem. Also, the documentation does not show they use regular expressions, adding to the work.

For instance, you could in principle build up an expression like this:

$(subst \\,\\\\,$(subst ",\", $(subst ',\', var)))

For more discussion,

  • Escaping comma and space in GNU Make
  • Can GNU make handle filenames with spaces?
  • GNU Make, double quotes and lists
like image 102
Thomas Dickey Avatar answered Oct 26 '25 07:10

Thomas Dickey



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!