Gentoo Archives: gentoo-dev

From: "Göktürk Yüksek" <gokturk@g.o>
To: gentoo-dev@l.g.o
Cc: "Amadeusz Żołnowski" <aidecoe@g.o>
Subject: Re: [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place
Date: Wed, 18 May 2016 22:28:27
Message-Id: 573CEC74.9000708@gentoo.org
In Reply to: [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place by aidecoe@gentoo.org
1 aidecoe@g.o:
2 > From: Amadeusz Żołnowski <aidecoe@g.o>
3 >
4 > awk doesn't have the -i option like sed and if editing file in place is
5 > desired, additional steps are required. eawk uses tmp file to make it
6 > look to the caller editing happens in place.
7 > ---
8 > eclass/eutils.eclass | 13 +++++++++++++
9 > 1 file changed, 13 insertions(+)
10 >
11 > diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
12 > index dbedffe..e331f1b 100644
13 > --- a/eclass/eutils.eclass
14 > +++ b/eclass/eutils.eclass
15 > @@ -20,6 +20,19 @@ _EUTILS_ECLASS=1
16 >
17 > inherit multilib toolchain-funcs
18 >
19 > +# @FUNCTION: eawk
20 > +# @USAGE: <file> <args>
21 > +# @DESCRIPTION:
22 > +# Edit file <file> in place with awk. Pass all arguments following <file> to
23 > +# awk.
24 > +eawk() {
25 > + local f="$1"; shift
26 > + local tmpf="$(emktemp)"
27 > +
28 > + cat "${f}" >"${tmpf}" || return 1
29 Why shell redirection with cat instead of cp? both are in coreutils.
30 Also, wouldn't the absence of 'die' cause silent breakages?
31
32 > + awk "$@" "${tmpf}" >"${f}"
33 > +}
34 > +
35 > # @FUNCTION: eqawarn
36 > # @USAGE: [message]
37 > # @DESCRIPTION:
38 >

Replies