Project

General

Profile

Bug #586

sed -i should take an "optional" argument

Added by Garrett D'Amore over 8 years ago. Updated almost 8 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
Category:
cmd - userland programs
Start date:
2010-12-29
Due date:
% Done:

0%

Estimated time:
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 worksNew2011-11-25

Actions
Has duplicate illumos gate - Bug #673: sed -i argument temp file should be optionalClosed2011-01-27

Actions

History

#1

Updated by Garrett D'Amore over 8 years ago

  • Assignee set to Roland Mainz
#2

Updated by Gordon Ross over 8 years ago

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

#3

Updated by Roland Mainz over 8 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.

#4

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

#5

Updated by Garrett D'Amore almost 8 years ago

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

#6

Updated by Yuri Pankov almost 8 years ago

  • Assignee set to Yuri Pankov

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

#7

Updated by Gordon Ross almost 8 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