Bug #586

sed -i should take an "optional" argument

Added by Garrett D'Amore over 3 years ago. Updated over 2 years ago.

Status:Resolved Start date:2010-12-29
Priority:Normal Due date:
Assignee:Yuri Pankov % Done:

0%

Category:cmd - userland programs Spent time: -
Target version:-
Difficulty:Medium Tags:needs-triage

Description

As much as I hate this....

GNU sed allows -i to take an argument, but does not require it. We should observe the same GNU behavior for increased compatibility.

Note that there is no elegant way (that I could discover) to properly support this with getopt... the optional argument should be optional only for -i, and should be treated as an argument to -i only when used without intervening spaces. This is apparently POSIX compliant, although it violates the CLIP standard.

I'd recommend making a minor enhancement to getopt to support this, or perhaps extending getopt_long.


Related issues

related to illumos gate - Bug #1815: sed -i "" no longer works New 2011-11-25
duplicated by illumos gate - Bug #673: sed -i argument temp file should be optional Closed 2011-01-27

History

Updated by Garrett D'Amore over 3 years ago

  • Assignee set to Roland Mainz

Updated by Gordon Ross over 3 years ago

One could also just not use getopt for this program.
Parsing argv options by hand is not that hard.

Updated by Roland Mainz over 3 years ago

Gordon Ross wrote:

One could also just not use getopt for this program. Parsing argv options by hand is not that hard.

Groan... please don't do that.
Right the Illumos userland is already suffering from the issues with non-uniform argument parsing and related problems. We're basically back to pre-SystemV times in that area. If we have a shared library function for this avoiding it is IMO bloat.

Updated by Yuri Pankov over 2 years ago

  • Assignee deleted (Roland Mainz)
  • Difficulty set to Medium
  • Tags set to needs-triage

This shouldn't be hard to "fix" (adding :: style options to our getopt), but we need to define which behavior we want -
current:

sed -i.bak ....
sed -i .bak ....
but not
sed -i ....

or GNU's:
sed -i ...
sed -i.bak
but not
sed -i .bak ...

I don't see a way to make it compatible for both cases.

Updated by Garrett D'Amore over 2 years ago

Unfortunately, we have to support the GNU syntax. Ick. But that's what is needed for compatibility.

Updated by Yuri Pankov over 2 years ago

  • Assignee set to Yuri Pankov

Much to my surprise, we have getopt_long() having all required functionality.. will post webrev shortly.

Updated by Gordon Ross over 2 years ago

  • Status changed from New to Resolved
changeset:   13507:aaf06453aff9
tag:         tip
user:        Yuri Pankov <yuri.pankov@nexenta.com>
date:        Fri Nov 04 12:59:45 2011 +0400
description:
    586 sed -i should take an "optional" argument
    Reviewed by: Andrew Stormont <Andrew.Stormont@nexenta.com>
    Reviewed by: Kartik Mistry <kartik.mistry@gmail.com>
    Approved by: Gordon Ross <gwr@nexenta.com>

Also available in: Atom PDF