How to convert a quote string to a regular one in a Makefile?

I am not sure if I described the question correctly, but I am currently solving this problem as follows.

QUOTEDSTR := "hello world"
NORMALSTR := $(shell echo $(QUOTEDSTR))

Is there a more built-in way that "make" can do this without invoking the shell? Thanks

+5
source share
4 answers

Another option:

NORMALSTR := $(patsubst "%",%,$(QUOTEDSTR))

A beta response will remove each quote in a row. The above solution will ONLY remove quotes that appear at the beginning and at the end. For instance:

QUOTEDSTR := -DTITLE=\"Title\"

A beta response will result in a value -DTITLE=\Title\when using the patsubst solution that value will not be changed.

It depends on what you want.

EDIT

- / @stefanct, . , , , . ^, - , .

: , , , :

# Get a variable S that contains a single space
E :=
S := $E $E

NORMALSTR := $(subst ^,$S,$(patsubst "%",%,$(subst $S,^,$(QUOTEDSTR))))

, ; , , , TAB.

+6

:

NORMALSTR := $(subst $\",,$(QUOTEDSTR))
+5

. patsubst "[f] inds , ", @MadScientist "hello world". , @Beta , .

, . , "hello "world"3" hello world"3. ... , , .

unquote .

quoted="hello world"

unquote = $(patsubst "%,%,$(patsubst %",%,$(1)))
#unquote = $(subst $\",,$(1))
#unquote = $(patsubst "%",%,$(1))
#unquote = $(shell echo $(1))

unquoted = $(call unquote,$(quoted))

$(info Variable quoted is $(quoted))
$(info Variable unquoted is $(unquoted))

( ) .

+1
NORMALSTR := $(subst $\",,$(QUOTEDSTR))

NORMALSTR := $(subst ",,$(QUOTEDSTR))

$\,

$\" .

",,$(QUOTEDSTR)) , ".

-1

All Articles