Sed options beyond -e are not mentioned or called out for usability or 
unreliability.  We found that -i in particular has inconsistent behavior, but 
the option is not strictly posix, so might be outside the scope of the autoconf 
documentation.

Gnu sed allows calling edit in place as

    sed -i 's/something/other/' a_file.txt

MacOS (perhaps other BSD sed implementations?) requires a suffix for in-place 
editing

    sed -i.backup 's/something/other/' a_file.txt

I don't know what the correct recommendation is, but personally, we are going 
to avoid using -i.

We are definitely not the first to find this: 
https://stackoverflow.com/questions/69438966/i-without-argument-is-gnu-sed-posix-option-bugged-or-bsd-sed-is-not-posix-co

That led me to the posix definition: 
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html

sed - stream editor - Open 
Group<https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html>
APPLICATION USAGE Regular expressions match entire strings, not just individual 
lines, but a <newline> is matched by '\n' in a sed RE; a <newline> is not 
allowed by the general definition of regular expression in POSIX.1-2017. Also 
note that '\n' cannot be used to match a <newline> at the end of an arbitrary 
input line; <newline> characters appear in the pattern space as a result of the 
N ...
pubs.opengroup.org
 only -e -f -n are defined.  The autoconf documentation mentions -e is not 
consistently implemented and not to rely on its behavior. However -f and -n are 
not mentioned. Are those consistent? Are other commonly used flags 
inconsistent? The autoconf docs do not have an opinion. -i is not mentioned in 
Posix, and so isn't completely reliable. I would suggest a callout similar to 
that of grep noting what flags (if any) are safe. If a non-posix example is 
needed, the above would be a reasonable example.

I'd be happy to help in any way I am able.

Thanks!


[cid:79e77e05-c6f2-475d-ae7e-becf2f43bbcc]

Daniel Locks

Lead Software Engineer

AMA Plaza

330 N. Wabash Ave., Suite 39300

Chicago, IL 60611-5885

M: (312) 969-0217

daniel.lo...@ama-assn.org<mailto:daniel.lo...@ama-assn.org>


Reply via email to