Subject: sed: empty label for :/b/t commands

From: Stephane Chazelas <[email-masked]>
Date: Thu, 13 Aug 2015 15:37:54 +0100

Hello.

Not really a bug as such, just a note of how a corner case of
GNU sed syntax parsing is being misused:

Recently, on unix.stackexchange.com, I've seen several times
people (might have been the same person every time) doing things
like:

sed ':;s/../../;t'

That is, define an empty label, and branch on it later on.

There's an example at
https://unix.stackexchange.com/revisions/223003/1
https://unix.stackexchange.com/a/223003

as per the documentation, it's not meant to work that way. The
label for ":" is not optional and "t" or "b" without label are
meant to jump to the end (start a new label).

I've warned that person that relying on an unspecified behaviour
was not a good idea as it may no longer work in the future, but
now if several people follow his example, that may mean it will
become a de-facto feature of GNU sed, and then the sed
maintainers would have to make sure it's not removed in future
versions (and document it).

So maybe it would be a good idea to either remove that
"feature" or make it an official one before its usage becomes
widespread.

In any case the:

sed ': label;s/../../;t label'

syntax is not portable anyway. The POSIX syntax being:

sed -e ': label' -e 's/../../;t label'

or

sed ':label
s/../../;t label'

Note that at the moment, GNU sed is not POSIX in that sed ':a;b'
is meant to define a label called "a;b", but that's going to change
in the next version of the spec where the behaviour will be
unspecified instead (so GNU sed doesn't need to be changed).
http://austingroupbugs.net/view.php?id=945

-- 
Stephane