getopt() argument permuting considered risky
Paul Eggert
eggert@CS.UCLA.EDU
Wed Aug 4 20:47:00 GMT 2004
"Michael T Kerrisk" <mtk-lists@gmx.net> writes:
> we can construct other examples
Sure, but you'd have a more convincing argument if you had real-world
examples rather than artificial ones.
> My point is that glibc's getopt() behaviour introduces a
> behaviour not present on other Unix systems.
No, similar behavior is present on other Unix systems, in some cases.
Here's Solaris 9, for example:
$ export PATH=/usr/xpg4/bin:/usr/bin
$ ls
$ echo foo >foo
$ sort foo -o bar
$ ls
bar foo
This behavior does not conform to POSIX 1003.1-2001 (which says that
"sort" must try to read a file named "-o"), but it's quite common on
older platforms and was even required by some earlier standards.
>> As a practical matter, portable scripts cannot assume the
>> POSIX-specified behavior here.
>
> You mean because of the glibc behaviour?
Yes, that's mainly it. Though I wouldn't be surprised if some other
implementations worked similarly.
> I don't have any broken scripts.
Cool. Then let's not worry about this now.
More information about the Libc-alpha
mailing list