From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 86AF0138262 for ; Wed, 18 May 2016 22:43:24 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DD89B14343; Wed, 18 May 2016 22:43:16 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 001BA1424D for ; Wed, 18 May 2016 22:43:15 +0000 (UTC) Received: from grubbs.orbis-terrarum.net (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 564EB340C23 for ; Wed, 18 May 2016 22:43:14 +0000 (UTC) Received: (qmail 9341 invoked by uid 10000); 18 May 2016 22:43:14 -0000 Date: Wed, 18 May 2016 22:43:14 +0000 From: "Robin H. Johnson" To: gentoo-dev@lists.gentoo.org Subject: Re: [gentoo-dev] [PATCH] eutils.eclass: Add awk wrapper - eawk - edit file in place Message-ID: <20160518224314.GH11269@orbis-terrarum.net> References: <1463606702-16578-1-git-send-email-aidecoe@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1463606702-16578-1-git-send-email-aidecoe@gentoo.org> User-Agent: Mutt/1.5.24 (2015-08-30) X-Archives-Salt: 4eab7734-beef-49a6-ab4b-00a7c3b464b0 X-Archives-Hash: 6eca5f53cf93d477d7a167d346a80948 On Wed, May 18, 2016 at 10:25:02PM +0100, aidecoe@gentoo.org wrote: > From: Amadeusz Żołnowski > > awk doesn't have the -i option like sed and if editing file in place is > desired, additional steps are required. eawk uses tmp file to make it > look to the caller editing happens in place. NAK. 1. If your AWK command has an error, then this clobbers the file, a better variant, with die, would be: awk "$@" "$f" >"${tmpf}" || die "awk failed..." cp -f "${tmpf}" "$f" || die "copy back failed" > # @USAGE: This calling format is also a problem if they intended to pass multiple files to the command, or if they do so accidentally. Eg, an unprotected glob in the first argument, eg: eawk foo* '/foobar/{$1="x"; print $0}' If foo1 and foo2 existed, this would be considered as: awk foo2 /foobar/{$1="x"; print $0}' foo1 which really will NOT have the desired effect. -- Robin Hugh Johnson Gentoo Linux: Dev, Infra Lead, Foundation Trustee & Treasurer E-Mail : robbat2@gentoo.org GnuPG FP : 11ACBA4F 4778E3F6 E4EDF38E B27B944E 34884E85 GnuPG FP : 7D0B3CEB E9B85B1F 825BCECF EE05E6F6 A48F6136