Bug #1815
opensed -i "" no longer works
0%
Description
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.
Related issues
Updated by Yuri Pankov over 10 years ago
I'm not sure what I can do about it - getopt_long's "optional argument" won't accept '-i ""' (I described it all in #586, and Garrett's decision was to be GNU sed compatible).
Updated by John Sonnenschein over 10 years ago
Then I'll just back the cset out of our tree. Having our current scripts not break is more important to me than having future scripts be more GNU compatible.
Updated by Yuri Pankov over 10 years ago
You could change sed invocations to have just '-i'...
Updated by John Sonnenschein over 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 over 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 over 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 over 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