Bug #586
closed
sed -i should take an "optional" argument
Added by Garrett D'Amore over 11 years ago.
Updated over 10 years ago.
Category:
cmd - userland programs
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.
- Assignee set to Roland Mainz
One could also just not use getopt for this program.
Parsing argv options by hand is not that hard.
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.
- 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.
Unfortunately, we have to support the GNU syntax. Ick. But that's what is needed for compatibility.
- Assignee set to Yuri Pankov
Much to my surprise, we have getopt_long() having all required functionality.. will post webrev shortly.
- 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