Discussion:
macOS sed
Add Reply
Rob Landley
2018-11-28 23:04:26 UTC
Reply
Permalink
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...)

Anyway, I'm happy to give a clearer error. _How_? (What does "uname -o" say on a
mac?) At the very leas I can make $SED default to "gsed" when [[ "$(uname -o")
=~ Mac ]] or some such, then at least the error is gsed missing. But that
assumes I'm detecting MacOS...

Rob

P.S. My commit to add an extra symlink dereferencing layer so you can alias
command names, this is one of the things I had vaguely in mind. So toybox can
provide _gsed_ for scripts that care. Toybox's build can't be the _only_ one on
macosx...
Rob Landley
2018-11-30 02:31:51 UTC
Reply
Permalink
Post by Rob Landley
Anyway, I'm happy to give a clearer error. _How_? (What does "uname -o" say on a
mac?)
"illegal option" :-)
just plain `uname` gets me "Darwin".
(given that `toybox uname -o` behaves differently than coreutils and
busybox ["Linux" versus "GNU/Linux"], and isn't even documented in
toybox, you might want to steer clear of that anyway.)
Sigh. Serves me right for looking at "man uname" and thinking the result meant
anything...

But [ "$(uname)" == "Darwin" ] I can work with.
Post by Rob Landley
At the very leas I can make $SED default to "gsed" when [[ "$(uname -o")
=~ Mac ]] or some such, then at least the error is gsed missing. But that
assumes I'm detecting MacOS...
the reason why i haven't sent you a patch is that there's a bunch of
other scripts that need similar treatment... should i factor it out
into scripts/findsed.sh and source that from the affected scripts?
What other scripts need this treatment?

Rob
Martin Kühl
2018-11-30 07:53:48 UTC
Reply
Permalink
Post by Rob Landley
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.
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.

- Martin

Loading...