[Toybox] macOS sed
enh
enh at google.com
Fri Nov 30 22:59:46 PST 2018
On Thu, Nov 29, 2018 at 11:54 PM Martin Kühl <martin.kuehl at gmail.com> wrote:
>
> On Fri, 30 Nov 2018 at 00:37, enh via Toybox <toybox at lists.landley.net> wrote:
> >
> > On Wed, Nov 28, 2018 at 3:04 PM Rob Landley <rob at landley.net> wrote:
> > >
> > > On 11/28/18 3:42 PM, enh via Toybox wrote:
> > > > according to https://stackoverflow.com/questions/12272065/sed-undefined-label-on-macos
> > > > macOS' sed only lets you branch backwards. this breaks mkflagsh and
> > > > getglobals in scripts/make.sh.
> > > >
> > > > i'm assuming the answer is "you'll need `brew install gnu-sed` to
> > > > bootstrap, and can use a toybox sed from then on", but should we give
> > > > a clearer error? something like "if you're on macOS but i can't find
> > > > gsed, suggest `brew install`"?
> > >
> > > Aha. That's why it had $SED.
> > >
> > > Wait, where in posix says you can only branch _backwards_? :label is a label you
> > > can jump to, it doesn't say it has to have already encountered it in the script.
> > > (Did I miss a curve in the reading again? I thought I'd read that one REALLY
> > > CLOSELY, although once again time has managed to go by since then...)
>
> It does not.
> However it _does_ say:
> > Editing commands other than {...}, a, b, c, i, r, t, w, :, and # can be followed by a <semicolon>, optional <blank> characters, and another editing command.
> (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html#tag_20_116_13_03)
>
> which means standalone labels like `-e ':notset'` are fine
> (https://github.com/landley/toybox/blob/6a6b12317149b41b163513e345f43167778f113f/scripts/make.sh#L147)
>
> but embedded labels like `…:clear;…` are not and break
> (https://github.com/landley/toybox/blob/6a6b12317149b41b163513e345f43167778f113f/scripts/make.sh#L197)
>
> Breaking them up into separate -e scripts should let them work on macOS.
(sorry, didn't see this until now.)
rob: is this a direction you'd want to go (assuming it works)? if so
i'll give this a try next time i'm at work.
that said, i do recall seeing another error about the T command, which
presumably refers to this:
T label
If no s/// has done a successful substitution since the last
input line was read and since the last t or T command, then
branch to label; if label is omitted, branch to end of script.
This is a GNU extension.
not sure whether that was just because it was already confused though.
(i basically can't read any sed more complicated than `s/x/y/g`, and i
usually struggle with the replacement syntax even then.)
> - Martin
More information about the Toybox
mailing list