Gentoo Archives: gentoo-dev

From: "Robin H. Johnson" <robbat2@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place
Date: Wed, 18 May 2016 22:43:24
Message-Id: 20160518224314.GH11269@orbis-terrarum.net
In Reply to: [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place by aidecoe@gentoo.org
1 On Wed, May 18, 2016 at 10:25:02PM +0100, aidecoe@g.o wrote:
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 NAK.
8
9 1.
10 If your AWK command has an error, then this clobbers the file, a better
11 variant, with die, would be:
12 awk "$@" "$f" >"${tmpf}" || die "awk failed..."
13 cp -f "${tmpf}" "$f" || die "copy back failed"
14
15 > # @USAGE: <file> <args>
16 This calling format is also a problem if they intended to pass multiple
17 files to the command, or if they do so accidentally.
18
19 Eg, an unprotected glob in the first argument, eg:
20 eawk foo* '/foobar/{$1="x"; print $0}'
21
22 If foo1 and foo2 existed, this would be considered as:
23 awk foo2 /foobar/{$1="x"; print $0}' foo1
24
25 which really will NOT have the desired effect.
26
27 --
28 Robin Hugh Johnson
29 Gentoo Linux: Dev, Infra Lead, Foundation Trustee & Treasurer
30 E-Mail : robbat2@g.o
31 GnuPG FP : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85
32 GnuPG FP : 7D0B3CEB E9B85B1F 825BCECF EE05E6F6 A48F6136

Replies