From owner-freebsd-current@freebsd.org Mon Mar 8 20:13:48 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 2F7B855606A; Mon, 8 Mar 2021 20:13:48 +0000 (UTC) (envelope-from carpeddiem@gmail.com) Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DvV0W1gjBz3PyR; Mon, 8 Mar 2021 20:13:46 +0000 (UTC) (envelope-from carpeddiem@gmail.com) Received: by mail-io1-f45.google.com with SMTP id k2so11375705ioh.5; Mon, 08 Mar 2021 12:13:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=NoIvf0hya5FBzhXr4KBKDN5VKuUnizqtWcuTC+FVVvs=; b=FhgsDtwlJHRRxM6Iq65L+HSnYXwEhGIYfxmYOoBRbO+0tFu9QOifJ9yWTlRVKYgpZS OeJTy4/4+Eucpi4TA30gb0t9nTur/OMUDg7m/uVxTlSm01zfOQG++U3s3XyFzaPqT+Pm di3JZzIfZtJpZ+mGw/BwcuWos1QuCN+MCqkKB/AoNw7zoQYyXEu+CTUg9PH87Qzm0mE/ jcflZk/BFRw8KjYpDa9zpJ9Ht57ybKM2KC2A1znb9vdhwj0fh7fWDV8IPlsz1dCxRIt2 bBBO11l0fw/TjHsnWUnUV+KaJpFg1ta1dBCOSZVpumxHzrHXKYJLm3+RZUUgrMyQoseP UXYw== X-Gm-Message-State: AOAM531ghX/2e/92CC89akv3JDVUClWTBUvZFLknmZaaTYuQ28s00qxr GQfIbYp8kHMEmGb0uNZ75mZdW21xMpddeUzoR6Xix2BZ6W3swg== X-Google-Smtp-Source: ABdhPJxBKEhCu4WYS6hz9jX7xhxIyXmY25tqv3QLuK9UbCMaCg5VVkknFJXYM/O1XVY6SD6DEUOQc0dlnuiNUNc3jOc= X-Received: by 2002:a6b:fc16:: with SMTP id r22mr19135510ioh.102.1615234424871; Mon, 08 Mar 2021 12:13:44 -0800 (PST) MIME-Version: 1.0 From: Ed Maste Date: Mon, 8 Mar 2021 15:13:19 -0500 Message-ID: Subject: Rationalizing sed -i/-I (in-place editing) argument handling To: FreeBSD Hackers , FreeBSD Current Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 4DvV0W1gjBz3PyR X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of carpeddiem@gmail.com designates 209.85.166.45 as permitted sender) smtp.mailfrom=carpeddiem@gmail.com X-Spamd-Result: default: False [-3.00 / 15.00]; RCVD_TLS_ALL(0.00)[]; ARC_NA(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FREEFALL_USER(0.00)[carpeddiem]; FROM_HAS_DN(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[209.85.166.45:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:209.85.128.0/17]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[freebsd.org]; NEURAL_HAM_LONG(-1.00)[-1.000]; SPAMHAUS_ZRD(0.00)[209.85.166.45:from:127.0.2.255]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; TO_DN_ALL(0.00)[]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCPT_COUNT_TWO(0.00)[2]; RCVD_IN_DNSWL_NONE(0.00)[209.85.166.45:from]; FORGED_SENDER(0.30)[emaste@freebsd.org,carpeddiem@gmail.com]; RWL_MAILSPIKE_POSSIBLE(0.00)[209.85.166.45:from]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:209.85.128.0/17, country:US]; MIME_TRACE(0.00)[0:+]; FROM_NEQ_ENVFROM(0.00)[emaste@freebsd.org,carpeddiem@gmail.com]; MAILMAN_DEST(0.00)[freebsd-hackers,freebsd-current] 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 20:13:48 -0000 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. 4. Continue accepting -I "" to specify no backup, but emit a warning suggesting the use of -I with no argument. 5. Retire the special case for -I "". These steps could be done over an extended period of time (such as one major release to another) - this is most important between steps 2 and 3. Please let me know what you think, and if there's something I've missed.