help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Confusion about $(shell) call and quoting


From: Eli Zaretskii
Subject: Re: Confusion about $(shell) call and quoting
Date: Tue, 16 May 2023 18:50:55 +0300

> Date: Tue, 16 May 2023 13:27:14 +0000
> From: tomasn@posteo.net
> 
> 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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]