sed -i "" no longer works
For a while, sed only accept -i with an argument. The workaround for this, which worked for a while, was 'sed -i "" ...', which Joyent relied up.
#586 broke the workaround, so now that doesn't work.
There is no way to use sed -i without a backup file which works with either version of sed.
Updated by John Sonnenschein almost 10 years ago
That misses the point entirely. Things should not break, especially without as much as a flag day.
Digging through every script we have looking for sed -i "" is a great deal of work compared to backing out a changeset that introduces a feature we neither use nor want.
Updated by Rich Lowe almost 10 years ago
The error we get from sed in this case is from all the way down in mf_gets at http://src.illumos.org/source/xref/illumos-gate/usr/src/cmd/sed/main.c#401 though. How's that the case if getopt_long can't cope?
I can't see how -i of explicit "" (that is, optarg is "") and -i with no arg (that is, optarg == NULL, and we assign inplace = "") differ?
Updated by Yuri Pankov almost 10 years ago
The problem here is in how getopt_long handles optional arguments. Optional argument should follow the option without any blanks, so -i"" will work, but in the -i "" case "" is assumed to be the 'script' or the 'file', returning an error..
Updated by Joshua M. Clulow almost 10 years ago
- Assignee set to Joshua M. Clulow
So, we can "preprocess" argv before handing it to getopt_long. It's not great, but it's pragmatic. Should give us the compatibility with GNU that we're after, while still using getopt_long for most of the work but also allowing "-i ''".
Diff + tests for review: https://gist.github.com/1394562