[Top][All Lists]

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

How to deal with filenames with spaces and dollar signs?

From: David Wuertele
Subject: How to deal with filenames with spaces and dollar signs?
Date: Thu, 9 Nov 2006 00:20:52 +0000 (UTC)
User-agent: Loom/3.14 (

I'm making a makefile library that has to stand up to some chaotic file naming
schemes.  I need make to copy some files around, only when necessary, without
getting confused by filenames with spaces and special (ie make-meaningful)

One problem I have is that make chokes on spaces and $ characters.  For example,
take this makefile:

all: clean source-files print-SOURCE_FILES

SOURCE_DIR := source-dir

.PHONY: clean
        rm -rf $(SOURCE_DIR)

.PHONY: source-files
        mkdir $(SOURCE_DIR)
        echo "one" > $(SOURCE_DIR)/one
        echo "two" > $(SOURCE_DIR)/two
        mkdir $(SOURCE_DIR)/three
        echo "four" > $(SOURCE_DIR)/three/four
        echo "five" > $(SOURCE_DIR)'/three/file! with? $$special %characters\
        mkdir $(SOURCE_DIR)'/three/directory! with? $$special %characters in:\'
        echo "six" > $(SOURCE_DIR)'/three/directory! with? $$special %charact\
ers in:'/six

SOURCE_FILES := $(shell find $(SOURCE_DIR))

        @echo $* = $($*)

When I run make on this makefile, here's what I see:

$ make
rm -rf source-dir
mkdir source-dir
echo "one" > source-dir/one
echo "two" > source-dir/two
mkdir source-dir/three
echo "four" > source-dir/three/four
echo "five" > source-dir'/three/file! with? $special %characters in:'
mkdir source-dir'/three/directory! with? $special %characters in:'
echo "six" > source-dir'/three/directory! with? $special %characters in:\'/six
SOURCE_FILES = source-dir source-dir/one source-dir/two source-dir/three
source-dir/three/four source-dir/three/file! with? %characters in:
source-dir/three/directory! with? %characters in:
source-dir/three/directory! with? %characters in:

I want the SOURCE_FILES variable to be a list of every directory and file in
the source-dir.  But files with spaces in their names will get split on the
spaces, and files with dollar signs in their names will lose a character.

I use this SOURCE_FILES variable to move files around using cpio.  I need to
give cpio accurate file listings, and I need for make to understand which files
are out of date.  Can anyone recommend a better solution than $(shell find


reply via email to

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