sedposixgnubsdgnu-sed

-i without argument: is GNU sed --posix option bugged or BSD sed is not POSIX-compliant?


This is mostly a curiosity question that arose here.

From the man page of GNU sed 4.8 I read

       --posix

              disable all GNU extensions.

so I understand that if a code like the following works, it means that -i without argument is allowed by POSIX:

sed --posix -i -n '1,25p' *.txt

On the other hand, the same code (with or without --posix) doesn't work for MacOS' BSD sed, because that version expects -i to be followed by an argument.

I can see only two mutually exclusive possibilities:

What is the truth?


Solution

  • --posix refers to the sed language itself, not the command line interface:

    GNU sed includes several extensions to POSIX sed. In order to simplify writing portable scripts, this option disables all the extensions that this manual documents, including additional commands.

    POSIX does not specify -i, so an implementation without it can still be POSIX-conforming.