From owner-freebsd-questions@freebsd.org Sat Mar 6 03:55:55 2021 Return-Path: Delivered-To: freebsd-questions@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 AE975573954 for ; Sat, 6 Mar 2021 03:55:55 +0000 (UTC) (envelope-from freebsd@dreamchaser.org) Received: from nightmare.dreamchaser.org (ns.dreamchaser.org [66.109.141.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "dreamchaser.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DsrP64KP1z4hqw for ; Sat, 6 Mar 2021 03:55:54 +0000 (UTC) (envelope-from freebsd@dreamchaser.org) Received: from breakaway.dreamchaser.org (breakaway [192.168.151.122]) by nightmare.dreamchaser.org (8.15.2/8.15.2) with ESMTP id 1263tpXo090972 for ; Fri, 5 Mar 2021 20:55:52 -0700 (MST) (envelope-from freebsd@dreamchaser.org) Subject: Re: sed -i empty argument compatibility issue To: freebsd-questions@freebsd.org References: <9178f6c5-631a-c2c2-c6b1-8def94a3397b@dreamchaser.org> <20210305142352297368817@bob.proulx.com> From: Gary Aitken Reply-To: freebsd@dreamchaser.org Message-ID: <606b8bfa-4fe5-883a-d7ac-99f41655f728@dreamchaser.org> Date: Fri, 5 Mar 2021 20:50:46 -0700 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <20210305142352297368817@bob.proulx.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (nightmare.dreamchaser.org [192.168.151.101]); Fri, 05 Mar 2021 20:55:52 -0700 (MST) X-Rspamd-Queue-Id: 4DsrP64KP1z4hqw X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of freebsd@dreamchaser.org designates 66.109.141.57 as permitted sender) smtp.mailfrom=freebsd@dreamchaser.org X-Spamd-Result: default: False [-3.28 / 15.00]; HAS_REPLYTO(0.00)[freebsd@dreamchaser.org]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[66.109.141.57:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+mx]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-questions@freebsd.org]; REPLYTO_ADDR_EQ_FROM(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; SPAMHAUS_ZRD(0.00)[66.109.141.57:from:127.0.2.255]; TO_DN_NONE(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.98)[-0.981]; DMARC_NA(0.00)[dreamchaser.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; RCVD_TLS_LAST(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:21947, ipnet:66.109.128.0/19, country:US]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[freebsd-questions] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Mar 2021 03:55:55 -0000 On 3/5/21 2:43 PM, Bob Proulx wrote: > Gary Aitken wrote: >> I'm trying to come up with a fix for a script in a port which >> invokes sed. The port comes from a linux environment, and the >> offending line looks like this: (This is in a cMake file.) ...> In order to port this then _something_ must be changed. As to what > must be changed that is up to you and judegement and the larger view > of everything in your environment. But off the top of my head these > different possibilities come to mind. > > 1. Edit the script and change this to that. This makes it run on > FreeBSD sed. Of course then this does not work the other direction. > > -COMMAND sed -i "/^# /d" "${outfile}" +COMMAND sed -i "" "/^# /d" > "${outfile}" > > 2. Use perl. Change that edit command to be this. This should work > the same everywhere that has perl. It does create a dependency upon > perl that might not have been present before. > > perl -i -lpe 'next if /^# /' "${outfile}" > > 3. Avoid -i and use a temporary file, just like in the old days. > However this introduces the need for temporary file handling. But > maybe that isn't important here. > > sed "/^# /d" "${outfile}" > "$tmpfile" && mv "$tmpfile" "${outfile}" > > 4. Introduce a "sed" wrapper in PATH that intercepts the call to the > real sed, detects this problematic usage case, and then DTRT does > the right thing with it. This wrapper could have all of the correct > temporary file handling needed to make this work. More involved to > do this but if I were faced with a large unknown code base and > expected to see a lot of this then I would consider it a good global > workaround for portability. > > 5. Hack a local FreeBSD sed version to detect this case and DTRT > with the option. > > 6. Compile GNU sed locally and install it in PATH earlier. This > would probably be a generally good option globally. However it's > possible you might run into portability problems in the reverse > case. Thanks for the list. That's two more than I came up with. I'm inclined to #2 (which I hadn't thought of) or #3. > Good luck! I'll be interested in hearing how things work out for > you. Thanks. I'm asking the authors for feedback. Gary