Gentoo Archives: gentoo-dev

From: Ulrich Mueller <ulm@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] readme.gentoo.eclass: expand variables when a file is used instead of setting DOC_CONTENTS in ebuild
Date: Mon, 01 Sep 2014 11:55:10
Message-Id: 21508.24213.162240.262192@a1i15.kph.uni-mainz.de
In Reply to: Re: [gentoo-dev] readme.gentoo.eclass: expand variables when a file is used instead of setting DOC_CONTENTS in ebuild by Pacho Ramos
1 >>>>> On Mon, 01 Sep 2014, Pacho Ramos wrote:
2
3 > What about
4 > while read; do eval echo "$REPLY"; done <
5 > "${FILESDIR}/README.gentoo-${SLOT%/*}" > "${T}"/README.gentoo || die
6
7 > ?
8
9 I'd say that any solution using eval should be avoided, because in
10 addition to variable expansion it does a lot of other unwanted things.
11 For example, stars, questions marks, and apostrophs will be special
12 and one would have to escape them.
13
14 > But, if I don't misunderstand, wouldn't it need an explicit
15 > substitution for each variable people tries to use? (I mean, for now
16 > it's $PF, but maybe other people want to expand $HOMEPAGE, $PN...)
17
18 Either that, or you could expand all @@ tokens with uppercase letters
19 inbetween. sed cannot read environment variables though, but something
20 like the following (untested!) awk script should work:
21
22 awk '{
23 while (match ($0, /@[[:upper:]]+@/)) {
24 v = substr ($0, RSTART+1, RLENGTH-2)
25 gsub ("@" v "@", ENVIRON[v])
26 }
27 print
28 }'
29
30 Ulrich