From owner-freebsd-current@freebsd.org Mon Mar 8 22:00:35 2021 Return-Path: Delivered-To: freebsd-current@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 75F5D55A2E7; Mon, 8 Mar 2021 22:00:35 +0000 (UTC) (envelope-from jmg@gold.funkthat.com) Received: from gold.funkthat.com (gate2.funkthat.com [208.87.223.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "gate2.funkthat.com", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DvXMk3kzhz3psJ; Mon, 8 Mar 2021 22:00:33 +0000 (UTC) (envelope-from jmg@gold.funkthat.com) Received: from gold.funkthat.com (localhost [127.0.0.1]) by gold.funkthat.com (8.15.2/8.15.2) with ESMTPS id 128M0Qvw032513 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 8 Mar 2021 14:00:26 -0800 (PST) (envelope-from jmg@gold.funkthat.com) Received: (from jmg@localhost) by gold.funkthat.com (8.15.2/8.15.2/Submit) id 128M0Q4F032512; Mon, 8 Mar 2021 14:00:26 -0800 (PST) (envelope-from jmg) Date: Mon, 8 Mar 2021 14:00:26 -0800 From: John-Mark Gurney To: Ed Maste Cc: FreeBSD Hackers , FreeBSD Current Subject: Re: Rationalizing sed -i/-I (in-place editing) argument handling Message-ID: <20210308220026.GK5246@funkthat.com> Mail-Followup-To: Ed Maste , FreeBSD Hackers , FreeBSD Current References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: FreeBSD 11.3-STABLE amd64 X-PGP-Fingerprint: D87A 235F FB71 1F3F 55B7 ED9B D5FF 5A51 C0AC 3D65 X-Files: The truth is out there X-URL: https://www.funkthat.com/ X-Resume: https://www.funkthat.com/~jmg/resume.html X-TipJar: bitcoin:13Qmb6AeTgQecazTWph4XasEsP7nGRbAPE X-to-the-FBI-CIA-and-NSA: HI! HOW YA DOIN? can i haz chizburger? User-Agent: Mutt/1.6.1 (2016-04-27) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (gold.funkthat.com [127.0.0.1]); Mon, 08 Mar 2021 14:00:26 -0800 (PST) X-Rspamd-Queue-Id: 4DvXMk3kzhz3psJ X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=none (mx1.freebsd.org: domain of jmg@gold.funkthat.com has no SPF policy when checking 208.87.223.18) smtp.mailfrom=jmg@gold.funkthat.com X-Spamd-Result: default: False [-0.51 / 15.00]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; FREEFALL_USER(0.00)[jmg]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[funkthat.com]; RBL_DBL_DONT_QUERY_IPS(0.00)[208.87.223.18:from]; AUTH_NA(1.00)[]; NEURAL_SPAM_SHORT(0.29)[0.285]; SPAMHAUS_ZRD(0.00)[208.87.223.18:from:127.0.2.255]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; TO_DN_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_SPF_NA(0.00)[no SPF record]; FORGED_SENDER(0.30)[jmg@funkthat.com,jmg@gold.funkthat.com]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:32354, ipnet:208.87.216.0/21, country:US]; FROM_NEQ_ENVFROM(0.00)[jmg@funkthat.com,jmg@gold.funkthat.com]; MAILMAN_DEST(0.00)[freebsd-hackers,freebsd-current]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Mar 2021 22:00:35 -0000 Ed Maste wrote this message on Mon, Mar 08, 2021 at 15:13 -0500: > A relatively minor but longstanding incompatibility between FreeBSD > and many other systems is the way sed handles backup files for > in-place editing -- sed's -I and -i options. GNU sed and other BSDs > accept an optional argument: -I.bak will save a backup file with a > .bak extension, and -I with no argument will not create a backup file. > FreeBSD currently accepts either -I.bak or -I .bak to save a backup > with the given extension, and -I "" (an empty argument) to specify no > backup. > > I've been tripped up by this in the past and I know many others have. > Most recently tobik@ filed PR 254091 for this. Now, I think a single > change to make -i/-I to be compatible with other sed implementations > in one step is too much of a POLA violation, but I think it can > reasonably be done in stages: > > 1. Update the man page to indicate that -i/-I should not have a space > between the flag and the extension. This is compatible with current > FreeBSD sed, other BSDs sed, GNU sed, and my proposed changes below. > No backup is still a special case and remains as -I "". > > I've opened https://reviews.freebsd.org/D29128 with proposed man page changes. > > 2. Continue accepting -I .bak, but emit a warning suggesting the use > of -I.bak instead. > > 3. Change -I/-i to getopt optional arguments, but keep a special case > for -I/-i "". At this point -I .bak becomes invalid as with other > seds, and specifying no backup can be done with either -I "" or -I > with no argument. This relies on an empty argument having no other > sensible interpretation. I will say that IMO, I really dislike a command line argument having an optional argument. It can cause parsing confusion and possibly security issues... Copying this behavior, IMO, is not good... So my vote is against this misfeature.. How is the program suppose to tell when the extension is "-e", or -e is a different option and not the argument to -I? -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."