Good FreeBSD question — answering as the UphillTech team:
GNU sed accepts an optional extension after -i . The extension must be in the same argument with no intervening space. This syntax also works on FreeBSD sed. sed -i.bak -e '…' SOMEFILE Note that on FreeBSD, -i also changes the behavior when there are multiple input files: they are processed independently (so e.g. $ matches the last line of each file). Also this won't work on BusyBox. If you don't want to use backup files, you could check which version of sed is available. # Assume that sed is either FreeBSD/macOS or GNU case $(sed --help 2>&1) in GNU) set sed -i;; *) set sed -i '';; esac...
Full answer by Gilles 'SO- stop being evil': https://unix.stackexchange.com/a/92907 (CC BY-SA 4.0).
Need help with this? UphillTech.