sed -i should take an "optional" argument
|Assignee:||Yuri Pankov||% Done:|
|Category:||cmd - userland programs|
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.
#3 Updated by Roland Mainz about 6 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 over 5 years ago
- Assignee deleted (
- 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 -
sed -i.bak .... sed -i .bak .... but not sed -i ....
sed -i ... sed -i.bak but not sed -i .bak ...
I don't see a way to make it compatible for both cases.
#7 Updated by Gordon Ross over 5 years ago
- Status changed from New to Resolved
changeset: 13507:aaf06453aff9 tag: tip user: Yuri Pankov <email@example.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 <firstname.lastname@example.org> Approved by: Gordon Ross <email@example.com>
Also available in: Atom