Gentoo Archives: gentoo-dev

From: Fabian Groffen <grobian@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] escaping variables in sed expressions
Date: Tue, 15 Apr 2008 11:14:52
Message-Id: 20080415111445.GO979@gentoo.org
In Reply to: Re: [gentoo-dev] escaping variables in sed expressions by "Santiago M. Mola"
1 On 15-04-2008 13:05:26 +0200, Santiago M. Mola wrote:
2 > On Tue, Apr 15, 2008 at 1:14 PM, Marijn Schouten (hkBst)
3 > <hkBst@g.o> wrote:
4 > >
5 > > Hi list,
6 > >
7 > > it seems I have been using some fragile sed expression and I'd like to tap
8 > > the collective
9 > > wisdom for avoiding doing that in the future.
10 > >
11 > > dev-scheme/slib-3.1.5-r1 currently does
12 > >
13 > > sed "s_prefix = /usr/local/_prefix = ${D}/usr/_" -i Makefile
14 > >
15 > > to make it not violate the sandbox. However a user had set
16 > > PORTAGE_TMPDIR=/home/gentoo_overflow/tmp causing the sed expression to
17 > > contain too may
18 > > underscores and failing.[1]
19 > >
20 > > There are several option to handle this. I could use a less common
21 > > delimiter or I could
22 > > escape it: ${D//_/\_} instead of ${D}. I could use a sed expression that
23 > > doesn't suffer
24 > > from this problem (thanks to dleverton):
25 > >
26 > > sed -ne '\_^prefix = /usr/local_!{p;d}' -e "iprefix = ${D}" -i Makefile
27 > >
28 > > Comments?
29 > >
30 >
31 > Currently is use ':' as sed delimiter when paths are involved. I'd
32 > also like to hear from you about proper delimiters if you think ':' is
33 > not safe enough.
34
35 I met one case where : was indeed a problem, but that was in
36 CFLAGS/LDFLAGS replacements. Some linkers accept (and do require)
37 arguments that are like "-mg:2512s".
38
39 > AFAIK, the only corner case which would make this fail would be
40 > Windows paths (C:/gentoo-prefix).
41
42 C:\ iirc, but Cygwin seems to map this as /cygdrive/C, Interix as
43 /dev/fs/C, command prompt I have no clue how portage could ever normally
44 work there. SpikeSource's SpikeWAMP uses Cygwin underneath, so
45 Portage/ebuilds will see the mapped paths only, never heard of any
46 problems from them regarding this either.
47
48
49 --
50 Fabian Groffen
51 Gentoo on a different level
52 --
53 gentoo-dev@l.g.o mailing list