5 ms·
-i is definitely not specificed by POSIX, but it supported on all those platforms with some small differences, for instance on OSX the backup extension (-i.bak)
by lhoursquentin 6y ago
-i is definitely not specificed by POSIX, but it supported on all those platforms with some small differences, for instance on OSX the backup extension (-i.bak) is not optional.
- gpanders 6y agoAmazingly, there is no portable way to use -i that works on both GNU and BSD sed implementations. Which means if you’re writing a portable script, you can’t use -i at all. (Would love to be proved wrong on this)
- bewuethr 6y agoAccording to Stack Overflow [1], this works: sed -i.bak 's/foo/bar/' filename [1]: https://stackoverflow.com/a/22084103/3266847 https://stackoverflow.com/a/22084103/3266847
- gpanders 6y agoThat works when specifying a backup extension, but not if you don’t want to create a backup file. sed -i ‘’ ... works on BSD sed but not GNU. Meanwhile: sed -i’’ ... sed -i ... both work on GNU but not BSD.
- bewuethr 6y agoWell, yes, you can't use it without creating a backup file, but it uses "-i" and is portable.