Gentoo Archives: gentoo-dev

From: "Amadeusz Żołnowski" <aidecoe@g.o>
To: "Robin H. Johnson" <robbat2@g.o>
Cc: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place
Date: Thu, 19 May 2016 21:51:11
Message-Id: 871t4xyax3.fsf@freja.aidecoe.name
In Reply to: Re: [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place by "Robin H. Johnson"
1 "Robin H. Johnson" <robbat2@g.o> writes:
2 > 1.
3 > If your AWK command has an error, then this clobbers the file, a
4 > better variant, with die, would be:
5 > awk "$@" "$f" >"${tmpf}" || die "awk failed..."
6 > cp -f "${tmpf}" "$f" || die "copy back failed"
7
8 Thanks! On the one hand it's a simple function, and on the other hand
9 there are several things which can go wrong. I will submit corrected
10 version with unit test.
11
12 Why '-f' is required?
13
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 I am aware of this. I considered before:
28
29 a) eawk files... -- awk_args...
30 b) eawk awk_args -- pattern files...
31
32 making '--' required, but that just complicates usage and function
33 itself. And anyway isn't it true for any other command with careless
34 glob use?
35
36 I have documented that function takes a file, not files. The effect of
37 misuse eawk would be awk error. Although maybe it would be useful to
38 support multiple files? Then I'd go for variant (b) probably.
39
40 Cheers,
41
42 --
43 Amadeusz Żołnowski

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies