From owner-freebsd-questions@freebsd.org Fri Mar 5 21:03:18 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 2768F5678DA for ; Fri, 5 Mar 2021 21:03:18 +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 4DsgF10YJmz3kGX for ; Fri, 5 Mar 2021 21:03:16 +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 125L38VV089607 for ; Fri, 5 Mar 2021 14:03:08 -0700 (MST) (envelope-from freebsd@dreamchaser.org) To: FreeBSD Mailing List Reply-To: freebsd@dreamchaser.org From: Gary Aitken Subject: sed -i empty argument compatibility issue Message-ID: <9178f6c5-631a-c2c2-c6b1-8def94a3397b@dreamchaser.org> Date: Fri, 5 Mar 2021 13:58:03 -0700 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 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 14:03:08 -0700 (MST) X-Rspamd-Queue-Id: 4DsgF10YJmz3kGX 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 [-1.30 / 15.00]; HAS_REPLYTO(0.00)[freebsd@dreamchaser.org]; ARC_NA(0.00)[]; NEURAL_SPAM_SHORT(1.00)[1.000]; 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]; RCVD_TLS_LAST(0.00)[]; TO_DN_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; DMARC_NA(0.00)[dreamchaser.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; 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: Fri, 05 Mar 2021 21:03:18 -0000 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.) COMMAND sed -i "/^# /d" "${outfile}" The issue is that linux sed expects the -I or -i extension modifier to immediately follow the -i. In the above line, the extension is deliberately missing to provide in-place editing. fbsd expects the extension to be separated from the -i by whitespace, or doesn't work properly when it is empty or immediately follows the -i: $ !ls ls -lt temp.tmp* -rw------- 1 garya garya 86 Mar 5 13:15 temp.tmp -rw------- 1 garya garya 86 Mar 5 13:15 temp.tmp_org $ sed -ifoo "/^# /d" temp.tmp (works on both fbsd & linux)) $ !ls ls -lt temp.tmp* -rw------- 1 garya garya 30 Mar 5 13:48 temp.tmp -rw------- 1 garya garya 86 Mar 5 13:15 temp.tmp_org -rw------- 1 garya garya 86 Mar 5 13:15 temp.tmpfoo $ cp -p temp.tmp_org temp.tmp $ sed -i"" "/^# /d" temp.tmp (works on linux but not fbsd) sed: 1: "temp.tmp": undefined label 'emp.tmp' $ sed -i "" "/^# /d" temp.tmp (works on fbsd but not linux) $ !ls ls -lt temp.tmp* -rw------- 1 garya garya 30 Mar 5 13:49 temp.tmp -rw------- 1 garya garya 86 Mar 5 13:15 temp.tmp_org -rw------- 1 garya garya 86 Mar 5 13:15 temp.tmpfoo So fbsd works with '-i ""' but linux requires '-i""' Does anyone know a work-around for this problem? Gary