From owner-freebsd-questions@FreeBSD.ORG Fri Oct 18 05:09:18 2013 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 689D14AF for ; Fri, 18 Oct 2013 05:09:18 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 065C32BF1 for ; Fri, 18 Oct 2013 05:09:17 +0000 (UTC) Received: from r56.edvax.de (port-92-195-74-65.dynamic.qsc.de [92.195.74.65]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id 3420E3CAC2; Fri, 18 Oct 2013 07:09:10 +0200 (CEST) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id r9I59308001957; Fri, 18 Oct 2013 07:09:04 +0200 (CEST) (envelope-from freebsd@edvax.de) Date: Fri, 18 Oct 2013 07:09:03 +0200 From: Polytropon To: Johan Kuuse Subject: Re: FreeBSD Make question Message-Id: <20131018070903.7ef5f8a8.freebsd@edvax.de> In-Reply-To: References: Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Polytropon List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Oct 2013 05:09:18 -0000 On Thu, 17 Oct 2013 18:43:33 +0200, Johan Kuuse wrote: > Hi, > > I'm trying to write a Makefile for FreeBSD Make (not GNU Make), with target > names containg spaces. > Example: > > MY_TARGET=/home/joe/directory name with spaces/hello.c > ${MY_TARGET}: > @echo ${.TARGET} > > The output is truncated to '/home/joe/directory' That is to be expected. :-) The space character is a _special_ character. It serves as a statement separator. (There are other special characters depending for example on the shell in use; other systems have different special characters that _could_ be valid in directory names or file names, but _should_ not be used because they could cause trouble when _improperly_ dealt with.) > Is there any possible way to escape this properly? There are, in fact, many possibilities. In an "O(n) manner" you can use the backslash \ to escape each of the spaces. They hereby lose their special meaning of being a statement separator: MY_TARGET=/home/joe/directory\ name\ with\ spaces/hello.c In an "O(1) manner" you can enclose the whole string in double quotes "...": MY_TARGET="/home/joe/directory name with spaces/hello.c" Single quotes '...' work similarly, with the exception that _if_ your string contains variables, they would not be expanded, but in your example, this does not apply. MY_TARGET='/home/joe/directory name with spaces/hello.c' The so-called backticks `...` have a totally different meaning (subshell result) and will not be considered here. :-) > I have read all the documentation I could find, and tried several ways > solving this problem, using quotes, escapes, substitutions. Note that even if you get the above statement working, there could be further annoying trouble ahead! If you intend to use special characters in file names (and directory names), there are a lot things you have to pay attention to. I suggest having a read of the following articles: David A. Wheeler: Filenames and Pathnames in Shell: How to do it correctly http://www.dwheeler.com/essays/filenames-in-shell.html as well as David A. Wheeler: Fixing Unix/Linux/POSIX Filenames: Control Characters (such as Newline), Leading Dashes, and Other Problems http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html > The output is the same if as use sh, bash, or tcsh, so it isn't shell > related. The Makefile executes a shell (usually sh) for each command to be executed. It handles its own statements "internally" (declaring dependencies and such). > Are spaces simply not possible to use in target names? They are possible, but you should not use them. It's also possible to use ~, *, newline, ; or - in file names, but you really _really_ should not do this. :-) -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...