Gentoo Archives: gentoo-dev

From: Frank Gruellich <frank@×××××××××.org>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] escaping variables in sed expressions
Date: Wed, 16 Apr 2008 17:17:57
Message-Id: 20080416171751.GT29406@der-frank.org
In Reply to: Re: [gentoo-dev] escaping variables in sed expressions by Marius Mauch
1 * Marius Mauch <genone@g.o> 15. Apr 08:
2 > On Tue, 15 Apr 2008 16:17:54 +0200
3 > Frank Gruellich <frank@×××××××××.org> wrote:
4 > > * Santiago M. Mola <coldwind@g.o> 15. Apr 08:
5 > > > On Tue, Apr 15, 2008 at 1:14 PM, Marijn Schouten (hkBst)
6 > > > Currently is use ':' as sed delimiter when paths are involved. I'd
7 > > > also like to hear from you about proper delimiters if you think ':'
8 > > > is not safe enough.
9 > > Even though it's probably stupid to use it, but ':' is a valid
10 > > character within a path. I've no solution for this problem, however.
11 > Valid maybe (but then pretty much every character is valid),
12
13 I've been a bigmouth so I couldn't sleep last night thinking about that
14 problem (which in fact happened to me sometimes). The very last
15 character I'd expect in a path would be the NUL char (\x00). I was not
16 able to create a filename or path containing it. (Anyone else?)
17 Unfortunately that stupid sed does not work with \x00 as delimiter...
18
19 But because a path will not contain a \x00 you can replace all
20 "$delimiter_of_your_dreams" with a \x00 and later change it back to the
21 original without adding any new.
22
23 Looks like:
24
25 (0) frank@bane [~] % echo '/foo/bar/foo:baz/baz bar/laber_rabarber/' |tr '/' '\0' |sed 's/a/o/g' |tr '\0' '/'
26 /foo/bor/foo:boz/boz bor/lober_roborber/
27 (0) frank@bane [~] %
28
29 Moving that to OP's problem he could maybe use something like:
30
31 tr '/' '\0' <Makefile |sed "s_prefix = /usr/local/_prefix = ${D}/usr/_" |tr '\0' '/' >Makefile.new
32
33 This obviously introduces the problem that a Makefile contains more than
34 just paths and there could be a \x00 somewhere... but... well...
35
36 > but colon is used as path delimiter in many other contexts (e.g.
37 > $PATH) so it's rather unlikely to be used.
38
39 I'm *very* paranoid. ;-)
40
41 Kind regards,
42 Frank.
43 --
44 Sigmentation fault
45 --
46 gentoo-dev@l.g.o mailing list

Replies

Subject Author
Re: [gentoo-dev] escaping variables in sed expressions Ciaran McCreesh <ciaran.mccreesh@××××××××××.com>