[Top][All Lists]

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

Re: ampersand in path name

From: Eric Blake
Subject: Re: ampersand in path name
Date: Wed, 01 Aug 2012 06:03:07 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120717 Thunderbird/14.0

On 07/31/2012 01:36 PM, K Richard Pixley wrote:
> I ran into a problem with an autoconf generated configure script today. 
> The problem is that the path to srcdir includes an ampersand, (several,
> actually).  This confuses the sed "s" commands which are written as
> "s&$foo&$bar&$baz"  as once they are variable expanded, they look like
> "s&x&&y&z&&w&z&&x&".

Is this only a problem with absolute file names, or is it also affecting
you with relative pathnames?  Generally, relative pathnames within a
project should be safe, and it is only absolute pathnames of the parent
directories where odd names can bite you.

> I've worked around it by forcing srcdir to be something else for now,
> although this is inconvenient because srcdir is generated by an
> automatic system.

Inconvenient or not, you'll probably have to continue doing this for a
while longer.

> At the very least, the generated configure script should check for the
> embedded character and produce some useful error message if one is found.

Indeed, this may be the easiest option.  Patches welcome.

> I've looked for a more permanent solution, but the problem is that just
> about any character one might select for the "s" command could,
> conceivably, be part of a valid unix path name these days.  The only
> solution I can think of offhand is to sed the pathname for the special
> character and escape it.  something like this:
> sed -e "s&"`echo $foo | sed -e "s&\&&\\\&&"`"&bar&baz

Improperly quoted and dangerous (the `` output has to be stored in a
temporary variable, otherwise on some broken shells, a Ctrl-C at the
wrong moment will end up invoking 'set -e "s&&bar&bax"').  But such
rewriting tricks have been used before.

Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

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