Re: Confusion about $(shell) call and quoting

Eli Zaretskii <[email protected]>
Newsgroups gmane.comp.gnu.make.general
Message-ID <[email protected]>
> Date: Tue, 16 May 2023 13:27:14 +0000
> From: [email protected]
> 
> Hello list
> 
> Given this directory structure
> 
> $ tree .
> .
> |-- D
> |   |-- f1.png
> |   `-- f2.png
> |-- Makefile
> `-- img.png
> 
> 1 directory, 4 files
> 
> and this makefile
> 
> $ cat Makefile
> PNGS := $(shell find D -name '*.png' -type f)
> 
> all : tellpng
> 
> .PHONY : tellpng
> tellpng :
> 	echo pngs: $(PNGS)
> 
> running make give this output
> 
> $ make
> echo pngs:
> pngs:
> 
> I was hoping to see the two png files in the D directory. If I change
> to
> 
> PNGS := $(shell find D -name "*.png" -type f)
> 
> (using double quotes) the two png files in the D directory are found.

You are using the MS-Windows port of Make natively on MS-Windows, so
you need to use the quoting that is supported by the native Windows
shell, cmd.exe

> Running make with the -d option I see the following differences of the
> CreateProcess call using single quotes, no quotes and double quotes
> around the -name argument (*.png), (editing the makefile).
> 
> With single quotes:
> CreateProcess(C:\progs\Git\usr\bin\find.exe,find D -name *.png -type 
> f,...)
> 
> With no quotes:
> CreateProcess(C:\progs\Git\usr\bin\sh.exe,C:/progs/Git/usr/bin/sh.exe -c 
> "find D -name *.png -type f",...)
> 
> With double quotes:
> CreateProcess(C:\progs\Git\usr\bin\sh.exe,C:/progs/Git/usr/bin/sh.exe -c 
> "find D -name \"*.png\" -type f",...)
> 
> In the first example (with single quotes), it looks as if find is
> called directly, and not shell?

Yes, because single quotes are not considered on MS-Windows to be
characters that require invocation via the shell.

> Should I learn from this that its better to use double quotes in a
> $(shell) call like this, or is there something strange going on?

On MS-Windows, _always_ use _only_ double quotes to quote shell
arguments.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.