Project

General

Profile

Bug #1815

sed -i "" no longer works

Added by Rich Lowe about 8 years ago. Updated about 8 years ago.

Status:
New
Priority:
Normal
Category:
-
Start date:
2011-11-25
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage

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

Related to illumos gate - Bug #586: sed -i should take an "optional" argumentResolved2010-12-29

Actions

History

#1

Updated by Yuri Pankov about 8 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).

#2

Updated by John Sonnenschein about 8 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.

#3

Updated by Yuri Pankov about 8 years ago

You could change sed invocations to have just '-i'...

#4

Updated by John Sonnenschein about 8 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.

#5

Updated by Yuri Pankov about 8 years ago

  • Assignee deleted (Yuri Pankov)
#6

Updated by Rich Lowe about 8 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?

#7

Updated by Yuri Pankov about 8 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..

#8

Updated by Joshua M. Clulow about 8 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

Also available in: Atom PDF