sed -i'' -e ... file
The BSD sed requires an argument to -i
, as opposed to GNU sed that accepts an optional argument to it.
FreeBSD sed man page:
-i extension
Edit files in-place similarly to -I
vs. GNU sed man page:
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
Note the brackets or lack of them.
Also, in shell -i''
is the same as just -i
, the quotes surrounding an empty string are just removed.
So, what sed
thinks you're asking is to create a backup file with the extension -e
, and unless you have write permission to the directory, too, you won't be able to do that.
Even without an argument or with an empty argument to -i
, sed
will probably create a temporary file where it writes the resulting output before moving it to the original name. At least GNU sed creates the temporary file in the same directory as the original, so again you need to have write permission to that directory.
$ strace -etrace=open,rename sed -i -e '1d' foo
[...]
open("foo", O_RDONLY) = 3
open("./sedD9J9tV", O_RDWR|O_CREAT|O_EXCL, 0600) = 4
rename("./sedD9J9tV", "foo") = 0
To work around that, you could create a temporary file elsewhere, and then move its contents to place:
$ sed -e '...' file > /tmp/file.tmp
$ cat /tmp/file.tmp > file && rm /tmp/file.tmp
wheel
then you don't have write permissions.wheel
and that they can read and write the file...