GNU bug report logs - #19842
sed bug: using -e instead of a literal newline in s replacement fails

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: sed; Severity: wishlist; Reported by: Evan Gates <evan.gates@HIDDEN>; Keywords: notabug moreinfo; dated Thu, 12 Feb 2015 01:52:01 UTC; Maintainer for sed is bug-sed@HIDDEN.
Added tag(s) moreinfo. Request was from Assaf Gordon <assafgordon@HIDDEN> to control <at> debbugs.gnu.org. Full text available.
Severity set to 'wishlist' from 'normal' Request was from Assaf Gordon <assafgordon@HIDDEN> to control <at> debbugs.gnu.org. Full text available.
Did not alter fixed versions and reopened. Request was from Debbugs Internal Request <help-debbugs@HIDDEN> to internal_control <at> debbugs.gnu.org. Full text available.

Message received at 19842 <at> debbugs.gnu.org:


Received: (at 19842) by debbugs.gnu.org; 26 Jan 2017 02:37:54 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jan 25 21:37:54 2017
Received: from localhost ([127.0.0.1]:43991 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1cWZwg-0003Yd-Ki
	for submit <at> debbugs.gnu.org; Wed, 25 Jan 2017 21:37:54 -0500
Received: from mail-qt0-f193.google.com ([209.85.216.193]:34923)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <assafgordon@HIDDEN>)
 id 1cWZwf-0003YO-HY; Wed, 25 Jan 2017 21:37:54 -0500
Received: by mail-qt0-f193.google.com with SMTP id f4so35515288qte.2;
 Wed, 25 Jan 2017 18:37:53 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=date:from:to:cc:subject:message-id:references:mime-version
 :content-disposition:in-reply-to:user-agent;
 bh=M5PiHZSfCItWuno8obw6sWSxTF72Jm3D00IYuptjcSA=;
 b=dNA0tNZNpvConyxEQ7gPwtvRIz/9Wytq7m3AAcBQweUqJ1kQzq11J1YwLVPeM5gDLt
 l2r6KedEz9EyHd9STmGMR+U72It2KTDil1iuKaHJiQGrSGf/Ncyv+9L0vbVyU9drTsm4
 s1nllx9vDbfgLhWvCBv1EPIZLDfdRIFvAJE+BQ2niGxhnyVq0dNeAZwABCkYvI+d826a
 kqiaOo798DaKWUs+V+Nvql4M8bH6VYMys9M8ltFkZpYAskNitkyK667ivEtaIv52xJAC
 2G579YhgFCTXZq03JrgVEd013eQPPJFV2UvluJELu3IaXnqhoHqyrp9BMbLqKa9EZwRI
 euTg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:date:from:to:cc:subject:message-id:references
 :mime-version:content-disposition:in-reply-to:user-agent;
 bh=M5PiHZSfCItWuno8obw6sWSxTF72Jm3D00IYuptjcSA=;
 b=YfDcZrqwUZGe6VolAtRRv9Z4QZdbr3FsYOV+lHdHdXrxXsKPbVhVq6/zztAUzz9QQO
 D7/G5jVnXVw+KoLoJ027iG5qXXQ3kPAh/1fGueAN+n4F0/36mJBcJKQKr2JzqNn/kxEJ
 Bu1ggynHWJCeFsEjzaAD0p38r3Sqd7kYacVodHKKigb4QCDweybk9m+ucL8hO8iNOrHJ
 PBq1rRVkfe6UcuyYJC/RFluaJPqko3S0enk3X+dKzhNN9H+K+fLOc112ug7zq940z0BB
 /VDVuD7w9WUB/67o7kksIgYZklF+xundCdRMN14CSx84ugbwYS1amcb8p9toEHWT4DRM
 NADw==
X-Gm-Message-State: AIkVDXIiZmumHTlgV2TJ+5SckPRRv19/j2NLskpWVkraC1MEJcoWKpTnlxQgjRlrdYiLrg==
X-Received: by 10.200.41.73 with SMTP id z9mr427998qtz.137.1485398267916;
 Wed, 25 Jan 2017 18:37:47 -0800 (PST)
Received: from gmail.com (housegordon.org. [104.236.108.240])
 by smtp.gmail.com with ESMTPSA id c83sm130806qkg.8.2017.01.25.18.37.46
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Wed, 25 Jan 2017 18:37:47 -0800 (PST)
Date: Thu, 26 Jan 2017 02:37:16 +0000
From: Assaf Gordon <assafgordon@HIDDEN>
To: Evan Gates <evan.gates@HIDDEN>
Subject: Re: bug#19842: sed bug: using -e instead of a literal newline in s
 replacement fails
Message-ID: <20170126023715.GA17506@HIDDEN>
References: <CAKvFXSCfJ43W=40o-+Rp+r6+RxqYyMxyrBNuGwEGgJ1UoGqGpA@HIDDEN>
 <3F8F80EF-4508-4723-9293-465B1E2BD37C@HIDDEN>
 <CAKvFXSAWxTtT-+nDnw-_x=fPacwXZLqVSYn277dLHSmgMu-CWA@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Disposition: inline
In-Reply-To: <CAKvFXSAWxTtT-+nDnw-_x=fPacwXZLqVSYn277dLHSmgMu-CWA@HIDDEN>
User-Agent: Mutt/1.5.23 (2014-03-12)
X-Spam-Score: 0.5 (/)
X-Debbugs-Envelope-To: 19842
Cc: 19842 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.5 (/)

reopen 19842
tags 19842 +moreinfo
thanks

Hello Evan,

On Wed, Jan 25, 2017 at 09:06:21AM -0800, Evan Gates wrote:
>I do not have a patch, but if you are interested I can ask on the
>Austin group list and see if there is any consensus and if so whether
>they would change the wording of the standard.

So let's re-open this for now, especially if you're going to raise this 
issue further on the Austin group. When you do, please send a note with 
the URL so we can keep track as well.

The behavior already differs between implementations, so it'll be 
intersting to see what's decided.

I assume that a discussion about this will cover all commands,
e.g. this as well:

  $ echo xyz | sed -e 'y/xyz/1\n3/'
  1
  3

versus:

  $ echo xyz | sed -e 'y/xyz/1\' -e '3/'
  sed: -e expression #1, char 8: unterminated `y' command


thanks,
 - assaf





Information forwarded to bug-sed@HIDDEN:
bug#19842; Package sed. Full text available.

Message received at 19842 <at> debbugs.gnu.org:


Received: (at 19842) by debbugs.gnu.org; 25 Jan 2017 17:06:50 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jan 25 12:06:50 2017
Received: from localhost ([127.0.0.1]:43091 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1cWR21-0001B9-Tg
	for submit <at> debbugs.gnu.org; Wed, 25 Jan 2017 12:06:50 -0500
Received: from mail-it0-f43.google.com ([209.85.214.43]:37021)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <evan.gates@HIDDEN>) id 1cWR20-0001Aw-0t
 for 19842 <at> debbugs.gnu.org; Wed, 25 Jan 2017 12:06:48 -0500
Received: by mail-it0-f43.google.com with SMTP id r185so16794714ita.0
 for <19842 <at> debbugs.gnu.org>; Wed, 25 Jan 2017 09:06:48 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=mime-version:in-reply-to:references:from:date:message-id:subject:to
 :cc; bh=AhA6qut6whU3jM+D8U2P/i/JlUNuX3bEZYXYKg18UCM=;
 b=NwMwlo+ZKc7VvFMiWhkMoDBqj/AsVH/eeEJtfX1xBRab5RCMPcMOInLaxFKgNm7J/E
 QhvvJcA1GpRfpo8vzgoAGJnHNLNXdUFn7lcUbYUzsL1PCEfvYz42LoJEADdIybGfyJ6J
 RRPONQAx3BW0vDupSHUfHphuEFf5sk3AnOx/j1pQcEXqylIionNRcij3QwCLtgYYomsC
 oWuZFeBiDV02Tun2FO9pdzLe1kpwYvVNOZB5Qgevil60N3dK4T81/ScCzQJub1nB/Ilt
 hJLbyYjc2Ufaf9olZUWzTkQOYN6r3ZGfu4ZvtWWsDqfNoLvVLOd8u+eSiohrKzsjXbTc
 0yvQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:in-reply-to:references:from:date
 :message-id:subject:to:cc;
 bh=AhA6qut6whU3jM+D8U2P/i/JlUNuX3bEZYXYKg18UCM=;
 b=FbwUrSVoN4WWJD6PHUPFKWBi7YHOG30DwFaKRMJZTe0bC7mgCIeFJIgKZ3WrizzfRK
 Tccic7VTbQo/tuSBYDG1DYH2QdmQgu0lQHZajAulsWOY+sr2GKg93gCH/Izm5Dnxmb8W
 hcAx4SFWE7mvLHkfEXEfVaDB7rEy5jHumdMMmjwFy9eGhnJk7iED41YrJjvyLOhy6cCE
 uJVO0hwTxpa3K2tq7ct44td+GZHcxWAt3fU4NgGzlnT/YtASxTfloNmGJdAKtHNRMnn0
 uu6mFOv0pnZpkZHm8HMexUmlsrc//otkVXLwob1dlEmlFWGAJ8fnKyA0MuHMln61CJgu
 5X9w==
X-Gm-Message-State: AIkVDXJ80knCxJnVSfNzC5oQoL1zOf/2myzfMfFZ21SXvGXGsNYKajVasdUuzBrSyNDobIwbIzLv2o0CX+9Bww==
X-Received: by 10.36.6.199 with SMTP id 190mr24371063itv.79.1485364002104;
 Wed, 25 Jan 2017 09:06:42 -0800 (PST)
MIME-Version: 1.0
Received: by 10.107.44.81 with HTTP; Wed, 25 Jan 2017 09:06:21 -0800 (PST)
In-Reply-To: <3F8F80EF-4508-4723-9293-465B1E2BD37C@HIDDEN>
References: <CAKvFXSCfJ43W=40o-+Rp+r6+RxqYyMxyrBNuGwEGgJ1UoGqGpA@HIDDEN>
 <3F8F80EF-4508-4723-9293-465B1E2BD37C@HIDDEN>
From: Evan Gates <evan.gates@HIDDEN>
Date: Wed, 25 Jan 2017 09:06:21 -0800
Message-ID: <CAKvFXSAWxTtT-+nDnw-_x=fPacwXZLqVSYn277dLHSmgMu-CWA@HIDDEN>
Subject: Re: bug#19842: sed bug: using -e instead of a literal newline in s
 replacement fails
To: Assaf Gordon <assafgordon@HIDDEN>
Content-Type: text/plain; charset=UTF-8
X-Spam-Score: -0.2 (/)
X-Debbugs-Envelope-To: 19842
Cc: 19842 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.2 (/)

On Tue, Jan 24, 2017 at 8:05 PM, Assaf Gordon <assafgordon@HIDDEN> wrote:
> Hello Evan and all,
>
> I'm triaging old sed bugs.
> (for past discussion, see https://bugs.gnu.org/19842 ).

Hi Assaf, thanks for taking the time to dig though this and respond.

> Second,
> Notice the backslash plays a role, indicating continuation for some
> implementations. Without backslash, '-e' are not always concatenated:
>
> Third,
> even in OpenBSD's sed which accepts this construct,
> it seems this is limited to 's'. It doesn't "just work"
> in all commands:

Yes the backslash is important and specific to the s command. In the
description of the s command POSIX says:

A line can be split by substituting a <newline> into it. The
application shall escape the <newline> in the replacement by preceding
it by a <backslash>.

So the examples without the backslash are irrelevant as are the
examples with the y command.

As for concatenation, POSIX says:

-e script
Add the editing commands specified by the script option-argument to
the end of the script of editing commands.

And more importantly:

If any -e or -f options are specified, the script of editing commands
shall initially be empty. The commands specified by each -e or -f
option shall be added to the script in the order specified. When each
addition is made, if the previous addition (if any) was from a -e
option, a <newline> shall be inserted before the new addition. The
resulting script shall have the same properties as the script operand,
described in the OPERANDS section.

This is a case where the previous addition was from a -e option, so a
newline should be inserted. After the newline is inserted the script
we have is

s/foo/bar\
baz/

And that "resulting script shall have the same properties..." means
that it should work the same as if it were in a file or in a single
argument with a literal newline.

> I'm marking this as 'done', but discussion can continue by replying to
> this thread. Better yet - if you have a patch that adds this
> functionality without causing regressions, we can look into
> incorporating it.

I do not have a patch, but if you are interested I can ask on the
Austin group list and see if there is any consensus and if so whether
they would change the wording of the standard.

Thank you for your time and work,
Evan




Information forwarded to bug-sed@HIDDEN:
bug#19842; Package sed. Full text available.
bug closed, send any further explanations to 19842 <at> debbugs.gnu.org and Evan Gates <evan.gates@HIDDEN> Request was from Assaf Gordon <assafgordon@HIDDEN> to control <at> debbugs.gnu.org. Full text available.
Added tag(s) notabug. Request was from Assaf Gordon <assafgordon@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 19842 <at> debbugs.gnu.org:


Received: (at 19842) by debbugs.gnu.org; 25 Jan 2017 04:06:07 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Jan 24 23:06:07 2017
Received: from localhost ([127.0.0.1]:41348 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1cWEqU-0007fS-Rd
	for submit <at> debbugs.gnu.org; Tue, 24 Jan 2017 23:06:07 -0500
Received: from mail-qt0-f193.google.com ([209.85.216.193]:34797)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <assafgordon@HIDDEN>)
 id 1cWEqT-0007et-GX; Tue, 24 Jan 2017 23:06:05 -0500
Received: by mail-qt0-f193.google.com with SMTP id a29so29391023qtb.1;
 Tue, 24 Jan 2017 20:06:05 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:content-transfer-encoding:date:subject:to:message-id
 :mime-version; bh=Sy41tmRvEWvFDc9OQCd8/8IUaO4GSfmYyLEbsRHWDCo=;
 b=KSZ9FZdqvU59TT84iBnFRlBeS1AOqmuZemmT0q8P3mfHrw0zUQGcPGxzUIl231Yizy
 3F0ylLFU8JYaB6DiHhhr+orfYdeJva4PY/jLQNO57aJNlOVMX+X06HtgGpaakR3VxgkC
 E0l7iG9DO6d94MNY+dd+P2PQPtA/RKn79M34xYjqTnr4GxghHV6k1ViNvUX0+PEIM2sO
 gkPsWNeHOxoo2LDFulWPkJ5HVfJ0CaEkiHWKQcGgjDEpTXKwqp+Auk6z4+rlXGy+LJq0
 JZugSjaPdH2l20REBEvH5X9peQdwil+RHrmLd8rjQucmB35MlrbNjWtWPpHvUogeppDa
 XIqw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:content-transfer-encoding:date:subject:to
 :message-id:mime-version;
 bh=Sy41tmRvEWvFDc9OQCd8/8IUaO4GSfmYyLEbsRHWDCo=;
 b=dtXeuZUMMNyOlG9CKmCa/KA0EfTttfHdgFGzMvakOjcBMRgXC3KeWNFsv8UJHe4Cka
 LJwtfMrXNr6JF/5AgcLRG86qOyPMFW8i7KbsATEcsO+xFJlSzAf0eX0pyRF9Zd5yGOaV
 yK2H9AGO7D4r/9Dkp2S6eZtkzsU1SPSET7dejFC0CQGdTlEi4BZAYuaP58rGLs6JisiK
 9KnzhW65bven9+UTzLEXjCoCXrPwz+DJXTGixMLKHmq2aR6X+cLOMa37OPIjzqMkj3vA
 ECsge1mr+XB+OlXfATE2K+ki87pDemDY6WuWfCHkJUg/1uzU69PRNZMijQpMYwb/ECv3
 lpWw==
X-Gm-Message-State: AIkVDXJUDYVLGazY3wspM1Q+domEk/roqRnflNAf76FZWZr3GHe6HBNHpKSz0ZBoZlsnUA==
X-Received: by 10.200.43.149 with SMTP id m21mr31411256qtm.213.1485317159982; 
 Tue, 24 Jan 2017 20:05:59 -0800 (PST)
Received: from ix.home (pool-100-37-92-116.nycmny.fios.verizon.net.
 [100.37.92.116])
 by smtp.gmail.com with ESMTPSA id b64sm17843472qkc.25.2017.01.24.20.05.59
 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128);
 Tue, 24 Jan 2017 20:05:59 -0800 (PST)
From: Assaf Gordon <assafgordon@HIDDEN>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Date: Tue, 24 Jan 2017 23:05:58 -0500
Subject: re: sed bug: using -e instead of a literal newline in s replacement
 fails
To: 19842 <at> debbugs.gnu.org
Message-Id: <3F8F80EF-4508-4723-9293-465B1E2BD37C@HIDDEN>
Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2102\))
X-Mailer: Apple Mail (2.2102)
X-Spam-Score: 0.5 (/)
X-Debbugs-Envelope-To: 19842
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.5 (/)

tag 19842 notabug
close 19842
stop


Hello Evan and all,

I'm triaging old sed bugs.
(for past discussion, see https://bugs.gnu.org/19842 ).


First,
for completeness, this is the behavior with various sed implementations:

$ echo foo | sed-gnu-4.3 -e 's/foo/bar\' -e 'baz/'
sed: -e expression #1, char 10: unterminated `s' command

$ echo foo | sed-netbsd-7.0 -e 's/foo/bar\' -e 'baz/'
bar
baz

$ echo foo | sed-freebsd-10 -e 's/foo/bar\' -e 'baz/'
bar
baz

$ echo foo | sed-openbsd-5.9 -e 's/foo/bar\' -e 'baz/'
barbaz

$ echo foo | sed-heirloom -e 's/foo/bar\' -e 'baz/'
Undefined label: az/

$ echo foo | sed-busybox -e 's/foo/bar\' -e 'baz/'
bar
baz


Second,
Notice the backslash plays a role, indicating continuation for some
implementations. Without backslash, '-e' are not always concatenated:

$ echo foo | sed-netbsd-7.0 -e 's/foo/bar' -e 'baz/'
sed-netbsd-7.0: 1: "s/foo/bar
": unescaped newline inside substitute pattern

$ echo foo | sed-freebsd-10 -e 's/foo/bar' -e 'baz/'
sed-freebsd-10: 1: "s/foo/bar
": unescaped newline inside substitute pattern

$ echo foo | sed-openbsd-5.9 -e 's/foo/bar' -e 'baz/'
barbaz

$ echo foo | sed-busybox -e 's/foo/bar' -e 'baz/'
sed: unmatched '/'



Third,
even in OpenBSD's sed which accepts this construct,
it seems this is limited to 's'. It doesn't "just work"
in all commands:

$ echo a | sed-openbsd-5.9 -e 'y/abc/123/'
1

$ echo a | sed-openbsd-5.9 -e 'y/abc/1\' -e '23/'
sed: 1: "y/abc/1\": unterminated transform target string

$ echo a | sed-openbsd-5.9 -e 'y/abc/1' -e '23/'
sed: 1: "y/abc/1": unterminated transform target string

as opposed to Busybox where it does work:

$ echo a | sed-busybox -e 'y/abc\' -e '/123/'
1



Lastly,
GNU sed does have one special case where trailing backslash
plays a role: in a/c/i commands. This is specifically done
to facilitate programs such as:

$ echo a | sed-gnu-4.3 -e '1i\' -e 'foobar'
foobar
a

$ echo a | sed-openbsd-5.9 -e '1i\' -e 'foobar'
foobara

$ echo a | sed-netbsd-7.0 -e '1i\' -e 'foobar'
sed-netbsd-7.0: 1: "foobar
": invalid command code f


As such,
I would say that this is not bug per-se in gnu sed.
It is not clear what is the correct behavior, and depending
on one's POSIX interpretation might even be undefined.

I'm marking this as 'done', but discussion can continue by replying to
this thread. Better yet - if you have a patch that adds this
functionality without causing regressions, we can look into
incorporating it.


regards,
- assaf










Information forwarded to bug-sed@HIDDEN:
bug#19842; Package sed. Full text available.

Message received at 19842 <at> debbugs.gnu.org:


Received: (at 19842) by debbugs.gnu.org; 22 Jul 2015 13:57:04 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jul 22 09:57:04 2015
Received: from localhost ([127.0.0.1]:56443 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ZHuW7-0006gg-E4
	for submit <at> debbugs.gnu.org; Wed, 22 Jul 2015 09:57:04 -0400
Received: from mailout06.t-online.de ([194.25.134.19]:60983)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <HBBroeker@HIDDEN>) id 1ZHuW3-0006gF-9Y
 for 19842 <at> debbugs.gnu.org; Wed, 22 Jul 2015 09:57:00 -0400
Received: from fwd03.aul.t-online.de (fwd03.aul.t-online.de [172.20.27.148])
 by mailout06.t-online.de (Postfix) with SMTP id D49D935FA2
 for <19842 <at> debbugs.gnu.org>; Wed, 22 Jul 2015 15:56:57 +0200 (CEST)
Received: from [192.168.2.25]
 (Zqq9U2ZYohomScVixRn9qRSXeed2ZgItxVASjurMm4lCBhUhOS6xutwxoqsIVM6wFv@[91.59.4.151])
 by fwd03.t-online.de with (TLSv1.2:ECDHE-RSA-AES256-SHA encrypted)
 esmtp id 1ZHuVs-2IfMCe0; Wed, 22 Jul 2015 15:56:48 +0200
To: 19842 <at> debbugs.gnu.org
From: =?UTF-8?Q?Hans-Bernhard_Br=c3=b6ker?= <HBBroeker@HIDDEN>
Subject: sed bug: using -e instead of a literal newline in s replacement fails
Message-ID: <55AFA11B.8090301@HIDDEN>
Date: Wed, 22 Jul 2015 15:56:43 +0200
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:38.0) Gecko/20100101
 Thunderbird/38.1.0
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-ID: Zqq9U2ZYohomScVixRn9qRSXeed2ZgItxVASjurMm4lCBhUhOS6xutwxoqsIVM6wFv
X-TOI-MSGID: 5d807576-829d-4b90-806b-cb6cc969e4d3
X-Spam-Score: -1.2 (-)
X-Debbugs-Envelope-To: 19842
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.2 (-)

 > The following is from POSIX[0]:

 > If any -e or -f options are specified, the script of editing commands
 > shall initially be empty. The commands specified by each -e or -f
 > option shall be added to the script in the order specified.

I think the solution to this mystery might be that the above statement 
is a good deal more strict than people have taken it.  It speaks of 
"commands specified by each -e".  Well, the example case's -e options 
_do_not_ each specify commands.  They each only specify part of one command.

So as I read this, this report is invalid by way of its expectations not 
being backed by the POSIX specification.




Information forwarded to bug-sed@HIDDEN:
bug#19842; Package sed. Full text available.

Message received at 19842 <at> debbugs.gnu.org:


Received: (at 19842) by debbugs.gnu.org; 18 Feb 2015 18:54:56 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 18 13:54:55 2015
Received: from localhost ([127.0.0.1]:48009 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YO9lv-0005qO-DJ
	for submit <at> debbugs.gnu.org; Wed, 18 Feb 2015 13:54:55 -0500
Received: from mail-ob0-f172.google.com ([209.85.214.172]:43555)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <evan.gates@HIDDEN>) id 1YO9lt-0005qG-FL
 for 19842 <at> debbugs.gnu.org; Wed, 18 Feb 2015 13:54:54 -0500
Received: by mail-ob0-f172.google.com with SMTP id nt9so5685590obb.3
 for <19842 <at> debbugs.gnu.org>; Wed, 18 Feb 2015 10:54:52 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
 h=mime-version:in-reply-to:references:from:date:message-id:subject:to
 :cc:content-type;
 bh=/3blsXNJKsFvQj6kVvDhTJOjweVvqB+T6kXUiqAa/28=;
 b=Xmdwc0zCiPkh1mt3TyTi3Ir+2TO4wPKfyR2PJCMk1yPMesBIhhjxrfcmMxUvf1uAxu
 7/UUe2w6e+2WicXv9I4SFK1Is5mYoI5RhVSFO1PCClEClaxNqd5dCuJAne/aPDv68Enp
 qZbdoMgGoGPegtyHY7Mw3wfrPMwISKll7NIMS77l3yCzgdExG9HSqzGYSskUHVSu/YDz
 Xvwcd2FD05SlS9OeGzOrAhHbt4o6mFGZ1AqxndlSSwI5Z9qIlnskAx9j/jQKkmu+4jOt
 JEF6FdWzWreEd95A1REiJ8B2w8gSAnWNsv0nWoHcLeBFQXU6ofMJz9mXezZIksCZ6PMM
 ALfw==
X-Received: by 10.202.2.79 with SMTP id 76mr357840oic.111.1424285692506; Wed,
 18 Feb 2015 10:54:52 -0800 (PST)
MIME-Version: 1.0
Received: by 10.202.90.193 with HTTP; Wed, 18 Feb 2015 10:54:32 -0800 (PST)
In-Reply-To: <20150218222445.1E4E.27F6AC2D@HIDDEN>
References: <20150218084850.9BED.27F6AC2D@HIDDEN>
 <CAKvFXSDsD6iFA8rU+z+ov59_mELyB8Skn3_eT1Y8gtihc_hLYw@HIDDEN>
 <20150218222445.1E4E.27F6AC2D@HIDDEN>
From: Evan Gates <evan.gates@HIDDEN>
Date: Wed, 18 Feb 2015 10:54:32 -0800
Message-ID: <CAKvFXSCX43D9WjZm-TuWygC16jKKbkEcQM=sjL3VKpW1Q3OB=g@HIDDEN>
Subject: Re: bug#19842: sed bug: using -e instead of a literal newline in s
 replacement fails
To: Norihiro Tanaka <noritnk@HIDDEN>
Content-Type: text/plain; charset=ISO-8859-1
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 19842
Cc: 19842 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

On Wed, Feb 18, 2015 at 5:24 AM, Norihiro Tanaka <noritnk@HIDDEN> wrote:
> Hi Evan,
>
> Sorry, I was wrong.  However, it is not written in anywhere that multiple
> -e and/or -f options must be analyzed after the concatenation.  It may be
> concatenated after each -e and/or -f options are parsed.
>
> By the way, /usr/bin/sed and /usr/xpg4/bin/sed on Solaris 11, /usr/bin/sed
> on HP-UX 11.23 also behave as same as GNU sed.  In other words, they also
> return an error code for following.
>
>   $ sed -e 's/foo/bar\' -e baz/
>
> Thanks,
> Noririro
>

Hi Norihiro,

The POSIX description of sed doesn't make any assumptions about the
inner workings of sed. It says nothing about analyzing, compiling,
building the internal structures, it only talks about adding to "the
script of editing commands" which will then be run. "The script of
editing commands" refers to a representation of the editing commands
in accord with the  descriptions that follow on the page, i.e. text
commands, a sed script. This is supported by the following line:

When each addition is made, if the previous addition (if any) was from
a -e option, a <newline> shall be inserted before the new addition.

The newline is mentioned because it is referring to the text
representation of the script (the only representation mentioned on the
page). It explains that all the parts from -e and -f should in effect
be concatenated to a single sed script, with newlines after the -e
option arguments. e.g.:

sed -e 's/foo/bar\' -e 'baz/'

and

printf %s\\n 's/foo/bar\' 'baz/' > script
sed -f script

should be identical, due to that newline.

Thanks,
Evan




Information forwarded to bug-sed@HIDDEN:
bug#19842; Package sed. Full text available.

Message received at 19842 <at> debbugs.gnu.org:


Received: (at 19842) by debbugs.gnu.org; 18 Feb 2015 13:24:56 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 18 08:24:56 2015
Received: from localhost ([127.0.0.1]:47026 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YO4ca-0004lT-2Z
	for submit <at> debbugs.gnu.org; Wed, 18 Feb 2015 08:24:56 -0500
Received: from mailgw06.kcn.ne.jp ([61.86.7.213]:40784)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <noritnk@HIDDEN>) id 1YO4cX-0004lE-DB
 for 19842 <at> debbugs.gnu.org; Wed, 18 Feb 2015 08:24:55 -0500
Received: from mxs01-s (mailgw1.kcn.ne.jp [61.86.15.233])
 by mailgw06.kcn.ne.jp (Postfix) with ESMTP id 47AE6E80608
 for <19842 <at> debbugs.gnu.org>; Wed, 18 Feb 2015 22:24:46 +0900 (JST)
X-matriXscan-loop-detect: 6ec6c226f25732862e14deae81106b03ddc5ca7a
Received: from mail07.kcn.ne.jp ([61.86.6.186]) by mxs01-s with ESMTP;
 Wed, 18 Feb 2015 22:24:45 +0900 (JST)
Received: from [10.120.1.13] (i118-21-128-66.s30.a048.ap.plala.or.jp
 [118.21.128.66])
 by mail07.kcn.ne.jp (Postfix) with ESMTPA id 92F0ED5009B;
 Wed, 18 Feb 2015 22:24:45 +0900 (JST)
Date: Wed, 18 Feb 2015 22:24:46 +0900
From: Norihiro Tanaka <noritnk@HIDDEN>
To: Evan Gates <evan.gates@HIDDEN>
Subject: Re: bug#19842: sed bug: using -e instead of a literal newline in s
 replacement fails
In-Reply-To: <CAKvFXSDsD6iFA8rU+z+ov59_mELyB8Skn3_eT1Y8gtihc_hLYw@HIDDEN>
References: <20150218084850.9BED.27F6AC2D@HIDDEN>
 <CAKvFXSDsD6iFA8rU+z+ov59_mELyB8Skn3_eT1Y8gtihc_hLYw@HIDDEN>
Message-Id: <20150218222445.1E4E.27F6AC2D@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-Mailer: Becky! ver. 2.65.07 [ja]
X-matriXscan-CTCmd-AV: Clean
X-matriXscan-Action: Approve
X-matriXscan: Uncategorized
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 19842
Cc: 19842 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

On Tue, 17 Feb 2015 16:23:54 -0800
Evan Gates <evan.gates@HIDDEN> wrote:

> Hi Norihiro,
> 
> Thanks for replying. I respectfully disagree with your interpretation.
> 
> The -e and -f options talk about "the script of editing commands" as
> the entire script/program that will run once sed starts reading input.
> Both -e and -f add commands to "the end of the script of editing
> commands." The line you quoted uses the exact same phrase:
> 
> 1) -e  script
> Add the editing commands specified by the script option-argument to
> the end of the script of editing commands.
> 2) -f  script_file
> Add the editing commands in the file script_file to the end of the
> script of editing commands.
> 3) If any -e or -f options are specified, the script of editing
> commands shall initially be empty.
> 
> I posit that "the script of editing commands" means the same thing in
> all three places. Therefore (3) means that the script/program that sed
> will run is empty before the first -e or -f.
> 
> Your interpretation would cause "the script of editing commands" to
> mean something different in (3) than it means in (1) and (2).
> 
> Thank you,
> Evan

Hi Evan,

Sorry, I was wrong.  However, it is not written in anywhere that multiple
-e and/or -f options must be analyzed after the concatenation.  It may be
concatenated after each -e and/or -f options are parsed.

By the way, /usr/bin/sed and /usr/xpg4/bin/sed on Solaris 11, /usr/bin/sed
on HP-UX 11.23 also behave as same as GNU sed.  In other words, they also
return an error code for following.

  $ sed -e 's/foo/bar\' -e baz/

Thanks,
Noririro





Information forwarded to bug-sed@HIDDEN:
bug#19842; Package sed. Full text available.

Message received at 19842 <at> debbugs.gnu.org:


Received: (at 19842) by debbugs.gnu.org; 18 Feb 2015 00:24:23 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Feb 17 19:24:23 2015
Received: from localhost ([127.0.0.1]:46718 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YNsRC-0006Bm-LN
	for submit <at> debbugs.gnu.org; Tue, 17 Feb 2015 19:24:22 -0500
Received: from mail-ob0-f174.google.com ([209.85.214.174]:49894)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <evan.gates@HIDDEN>) id 1YNsRA-0006BX-Cb
 for 19842 <at> debbugs.gnu.org; Tue, 17 Feb 2015 19:24:21 -0500
Received: by mail-ob0-f174.google.com with SMTP id wo20so58653562obc.5
 for <19842 <at> debbugs.gnu.org>; Tue, 17 Feb 2015 16:24:14 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
 h=mime-version:in-reply-to:references:from:date:message-id:subject:to
 :cc:content-type;
 bh=F/OT1Q7ex1IJpx3zbNHLIvwSJe0Yoat+8Xln0x3WqG0=;
 b=OM6Rx8FXFwncn3kcLLhCoF1vJesCXX0MqW1pKnkiV3AhBVxu/ayEvdXhsc+UHvInsP
 vQCAJu5YiQNc+6W2+aYFzdEQfqY36BYEZtYnDdPFwDqk2/r7tboakiuajMJCoktGm73q
 0WrEYbSX246N4vW6Fp8eD9ZxD5lhMusRg8+Vt7WOXztpwZi+2xI0QPaH8kB+tV/8djM3
 S6UzxZcu16nQmtM3WeCZT77X0qdayGZhlfJP2LgrshqdxojRBeKLIokihEsaMXcnIIhL
 /guRrv6VyrjWNEYdRTfAlEkE18hBZ6ZGcKg3zJei5S7lDG9MOZxSRGEzOT66xQ3mnYa9
 Y5ag==
X-Received: by 10.182.27.162 with SMTP id u2mr2567418obg.46.1424219054493;
 Tue, 17 Feb 2015 16:24:14 -0800 (PST)
MIME-Version: 1.0
Received: by 10.202.90.193 with HTTP; Tue, 17 Feb 2015 16:23:54 -0800 (PST)
In-Reply-To: <20150218084850.9BED.27F6AC2D@HIDDEN>
References: <CAKvFXSCfJ43W=40o-+Rp+r6+RxqYyMxyrBNuGwEGgJ1UoGqGpA@HIDDEN>
 <20150218084850.9BED.27F6AC2D@HIDDEN>
From: Evan Gates <evan.gates@HIDDEN>
Date: Tue, 17 Feb 2015 16:23:54 -0800
Message-ID: <CAKvFXSDsD6iFA8rU+z+ov59_mELyB8Skn3_eT1Y8gtihc_hLYw@HIDDEN>
Subject: Re: bug#19842: sed bug: using -e instead of a literal newline in s
 replacement fails
To: Norihiro Tanaka <noritnk@HIDDEN>
Content-Type: text/plain; charset=ISO-8859-1
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 19842
Cc: 19842 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

On Tue, Feb 17, 2015 at 3:48 PM, Norihiro Tanaka <noritnk@HIDDEN> wrote:
> Hi,
>
> I interprete following as multiple `-e' option does not merge fragments
> of two commands.
>
>   # If any -e or -f options are specified, the script of editing commands
>   # shall initially be empty.
>
> i.e. the command by first -e option is parsed without the completion,
> the buffer is initialized into empty before next -e option.
>
> Thanks,
> Norihiro
>

Hi Norihiro,

Thanks for replying. I respectfully disagree with your interpretation.

The -e and -f options talk about "the script of editing commands" as
the entire script/program that will run once sed starts reading input.
Both -e and -f add commands to "the end of the script of editing
commands." The line you quoted uses the exact same phrase:

1) -e  script
Add the editing commands specified by the script option-argument to
the end of the script of editing commands.
2) -f  script_file
Add the editing commands in the file script_file to the end of the
script of editing commands.
3) If any -e or -f options are specified, the script of editing
commands shall initially be empty.

I posit that "the script of editing commands" means the same thing in
all three places. Therefore (3) means that the script/program that sed
will run is empty before the first -e or -f.

Your interpretation would cause "the script of editing commands" to
mean something different in (3) than it means in (1) and (2).

Thank you,
Evan




Information forwarded to bug-sed@HIDDEN:
bug#19842; Package sed. Full text available.

Message received at 19842 <at> debbugs.gnu.org:


Received: (at 19842) by debbugs.gnu.org; 17 Feb 2015 23:48:57 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Feb 17 18:48:57 2015
Received: from localhost ([127.0.0.1]:46702 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YNrsu-00040P-DA
	for submit <at> debbugs.gnu.org; Tue, 17 Feb 2015 18:48:56 -0500
Received: from mailgw06.kcn.ne.jp ([61.86.7.213]:33134)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <noritnk@HIDDEN>) id 1YNrsq-00040D-Ub
 for 19842 <at> debbugs.gnu.org; Tue, 17 Feb 2015 18:48:54 -0500
Received: from mxs02-s (mailgw2.kcn.ne.jp [61.86.15.234])
 by mailgw06.kcn.ne.jp (Postfix) with ESMTP id 7124CE805AE
 for <19842 <at> debbugs.gnu.org>; Wed, 18 Feb 2015 08:48:49 +0900 (JST)
X-matriXscan-loop-detect: c7838a0692633ce01a0aa40234f0b954e46c18ed
Received: from mail03.kcn.ne.jp ([61.86.6.182]) by mxs02-s with ESMTP;
 Wed, 18 Feb 2015 08:48:49 +0900 (JST)
Received: from [10.120.1.9] (i118-21-128-66.s30.a048.ap.plala.or.jp
 [118.21.128.66])
 by mail03.kcn.ne.jp (Postfix) with ESMTPA id 1E137141009A;
 Wed, 18 Feb 2015 08:48:49 +0900 (JST)
Date: Wed, 18 Feb 2015 08:48:50 +0900
From: Norihiro Tanaka <noritnk@HIDDEN>
To: Evan Gates <evan.gates@HIDDEN>
Subject: Re: bug#19842: sed bug: using -e instead of a literal newline in s
 replacement fails
In-Reply-To: <CAKvFXSCfJ43W=40o-+Rp+r6+RxqYyMxyrBNuGwEGgJ1UoGqGpA@HIDDEN>
References: <CAKvFXSCfJ43W=40o-+Rp+r6+RxqYyMxyrBNuGwEGgJ1UoGqGpA@HIDDEN>
Message-Id: <20150218084850.9BED.27F6AC2D@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-Mailer: Becky! ver. 2.65.07 [ja]
X-matriXscan-CTCmd-AV: Clean
X-matriXscan-Action: Approve
X-matriXscan: Uncategorized
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 19842
Cc: 19842 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

On Wed, 11 Feb 2015 17:20:24 -0800
Evan Gates <evan.gates@HIDDEN> wrote:

> Hello,
> 
> sed 's/foo/bar\
> baz/'
> 
> works as expected. But using multiple -e instead of a literal newline fails:
> 
> $ sed -e 's/foo/bar\' -e baz/
> sed: -e expression #1, char 10: unterminated `s' command
> 
> The following is from POSIX[0]:
> 
> If any -e or -f options are specified, the script of editing commands
> shall initially be empty. The commands specified by each -e or -f
> option shall be added to the script in the order specified. When each
> addition is made, if the previous addition (if any) was from a -e
> option, a <newline> shall be inserted before the new addition. The
> resulting script shall have the same properties as the script operand,
> described in the OPERANDS section.
> 
> My reading of that leads me to believe that the two commands should
> create identical scripts, but GNU sed seems to me interpreting the
> script before the addition of the newline and second -e's argument.
> 
> Is this a bug or desired behavior?
> 
> Thanks,
> Evan
> 
> $ sed --version
> sed (GNU sed) 4.2.2
> Copyright (C) 2012 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
> 
> Written by Jay Fenlason, Tom Lord, Ken Pizzini,
> and Paolo Bonzini.
> GNU sed home page: <http://www.gnu.org/software/sed/>.
> General help using GNU software: <http://www.gnu.org/gethelp/>.
> E-mail bug reports to: <bug-sed@HIDDEN>.
> Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
> 
> [0] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_04

Hi,

I interprete following as multiple `-e' option does not merge fragments
of two commands.

  # If any -e or -f options are specified, the script of editing commands
  # shall initially be empty.

i.e. the command by first -e option is parsed without the completion,
the buffer is initialized into empty before next -e option.

Thanks,
Norihiro





Information forwarded to bug-sed@HIDDEN:
bug#19842; Package sed. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 12 Feb 2015 01:51:42 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Feb 11 20:51:42 2015
Received: from localhost ([127.0.0.1]:40453 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.80)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1YLiwP-0008Az-BZ
	for submit <at> debbugs.gnu.org; Wed, 11 Feb 2015 20:51:42 -0500
Received: from eggs.gnu.org ([208.118.235.92]:41200)
 by debbugs.gnu.org with esmtp (Exim 4.80)
 (envelope-from <evan.gates@HIDDEN>) id 1YLiSb-0007T1-Rw
 for submit <at> debbugs.gnu.org; Wed, 11 Feb 2015 20:20:54 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <evan.gates@HIDDEN>) id 1YLiSV-0004Fe-JY
 for submit <at> debbugs.gnu.org; Wed, 11 Feb 2015 20:20:48 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM,
 T_DKIM_INVALID autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:35666)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <evan.gates@HIDDEN>) id 1YLiSV-0004Fa-HP
 for submit <at> debbugs.gnu.org; Wed, 11 Feb 2015 20:20:47 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:42922)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <evan.gates@HIDDEN>) id 1YLiSU-0002hn-Fb
 for bug-sed@HIDDEN; Wed, 11 Feb 2015 20:20:47 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <evan.gates@HIDDEN>) id 1YLiST-0004FL-Dy
 for bug-sed@HIDDEN; Wed, 11 Feb 2015 20:20:46 -0500
Received: from mail-ob0-x22b.google.com ([2607:f8b0:4003:c01::22b]:42570)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <evan.gates@HIDDEN>) id 1YLiST-0004FH-9D
 for bug-sed@HIDDEN; Wed, 11 Feb 2015 20:20:45 -0500
Received: by mail-ob0-f171.google.com with SMTP id gq1so7092223obb.2
 for <bug-sed@HIDDEN>; Wed, 11 Feb 2015 17:20:44 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
 h=mime-version:from:date:message-id:subject:to:content-type;
 bh=ZTNbL43pMSBaied31umr1bxs/NVb1o6J1PmBQK3518U=;
 b=No3TedPGqcAI5gt/IbNmKNiCj/JNaWLlpjNvKxW4/yXrG2Ikv3UwLXdrMYoGNA9bdK
 cH6tlzDUfUr8l9Ggl6aWllw/stNFvIL4yawvZpvMt5eab6WFI+uckVnBfJSDqGko5Jv2
 ZLQQLD/hMOBOswsc6xDJCnqyV7IFr3WbqgF2LEdoSK8Byo4mtXO+NqceEcP1LyzcfLqP
 Ya7zeGaDOC21wT4Iy0Be0WtT3sXkRMvECS4XXxqWZg5S5IkPe+MQu1/WLELsr2leDON4
 yvxyaP35Eq+BeP4j29DHFRjYhqlSTtsICl6/lDlarGOrkVujK4jx+oZFF64yVrdMV986
 D3jA==
X-Received: by 10.60.145.212 with SMTP id sw20mr990258oeb.39.1423704044635;
 Wed, 11 Feb 2015 17:20:44 -0800 (PST)
MIME-Version: 1.0
Received: by 10.202.90.193 with HTTP; Wed, 11 Feb 2015 17:20:24 -0800 (PST)
From: Evan Gates <evan.gates@HIDDEN>
Date: Wed, 11 Feb 2015 17:20:24 -0800
Message-ID: <CAKvFXSCfJ43W=40o-+Rp+r6+RxqYyMxyrBNuGwEGgJ1UoGqGpA@HIDDEN>
Subject: sed bug: using -e instead of a literal newline in s replacement fails
To: bug-sed@HIDDEN
Content-Type: text/plain; charset=ISO-8859-1
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
 (bad octet value).
X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address
 (bad octet value).
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -4.0 (----)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Wed, 11 Feb 2015 20:51:39 -0500
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -4.0 (----)

Hello,

sed 's/foo/bar\
baz/'

works as expected. But using multiple -e instead of a literal newline fails:

$ sed -e 's/foo/bar\' -e baz/
sed: -e expression #1, char 10: unterminated `s' command

The following is from POSIX[0]:

If any -e or -f options are specified, the script of editing commands
shall initially be empty. The commands specified by each -e or -f
option shall be added to the script in the order specified. When each
addition is made, if the previous addition (if any) was from a -e
option, a <newline> shall be inserted before the new addition. The
resulting script shall have the same properties as the script operand,
described in the OPERANDS section.

My reading of that leads me to believe that the two commands should
create identical scripts, but GNU sed seems to me interpreting the
script before the addition of the newline and second -e's argument.

Is this a bug or desired behavior?

Thanks,
Evan

$ sed --version
sed (GNU sed) 4.2.2
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jay Fenlason, Tom Lord, Ken Pizzini,
and Paolo Bonzini.
GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-sed@HIDDEN>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.

[0] http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_04




Acknowledgement sent to Evan Gates <evan.gates@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-sed@HIDDEN. Full text available.
Report forwarded to bug-sed@HIDDEN:
bug#19842; Package sed. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.