2015-08-10 23:53:11 -0700, [email protected] [sed-users]:
> GNU sed supports comments starting any column. In other words,
> the following script works:
>
>
> s/x/y/ # Silly comment 1
> s/a/b/ # Silly comment 2
>
>
> I am told that some sed versions only support comments that start in column 1. I don't doubt it. I suppose those sed versions would crash or otherwise malfunction on the above script. Seems primitive to me. :( And coming from a sed user, calling something primitive is saying something. :)
>
>
> The POSIX specification does not restrict comments to start
> in column 1. Thus, POSIX says comments can start in any
> column. Thus, this difference between GNU and other versions
> seems not a "GNU extension".
It says # is a command though and that it must be separated from
another command with ; or newline (optionaly followed/preceded
by blanks) like other commands, and that some commands can't be
followed by other commands (other than on a separate line or
with a new -e expression).
s/x/y/ # comment
is wrong. It's attempting to use the (unspecified) # flag to the
s command.
s/x/y/; # comment
would be POSIX AFAICT.
s/x/y/w file; # comment
Writes the pattern space after successful substitution to the
file called "file; # comment" even with GNU sed.
/x/{ =; } # comment
is not POSIX.
b foo;#x
jumps to the "foo;#x" label in a POSIX sed (will change in the
next POSIX spec where the behaviour will be unspecified
instead and GNU sed will no longer be non-compliant in that
regard).
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
>
>
> So here are my questions for the experts on the egroup:
>
>
> 1) Which actively maintained sed versions require comments to start in column 1?
/usr/xpg4/bin/sed on Solaris 10 and Solaris 11 at least do:
s11:~$ echo x | sed ' #'
x
s11:~$ echo x | command -p sed ' #'
sed: # is an unrecognized command.
s11:(2)~$ echo x | command -p sed '#'
x
> 2) I have nothing against these other versions. The more
> versions, the better. But if POSIX says comments can start in
> any column, why aren't these other versions "fixed up" to be
> compliant, or even to be adequate? It shouldn't be all that
> difficult. If they aren't "fixed up", are they really
> actively maintained?
What's strange is that /usr/bin/sed on Solaris doesn't have the
issue. While /usr/xpg4/bin/sed (aka command -p sed) is meant to
be POSIX compliant.
I've raised the question on the Austin Group mailing list:
http://thread.gmane.org/gmane.comp.standards.posix.austin.general/11287
and it appears that's how it was specified in SVID before the
POSIX days.
It looks like Solaris forgot to update that part and that the
conformance tests do not have a test case for that.
Now that it's been noted by some Solaris guys on that mailing
list, it may be fixed in the future.
> 3) Given POSIX, is it fair to say, "sed supports # comments starting any column"?
Whether it can start on a given column depends on what is on the
columns left to it on the same line/expression as said above.
> 4) What other standard overrides POSIX, and justifies other seds not getting "fixed up"?
None that I'm aware. I can imagine a standard leaving it
unspecified if # is not in first position, but not one requiring
sed to fail there. IOW, I can't imagine a standard that would
prevent a sed implementation from being fixed.
I can't see what could break if a sed
implementation changed to stop outputting an error on
sed ' # comment'
On the other hand,
sed 'w file # comment'
Can't be changed to allow "# comment" to be treated as a comment
as that would break scripts that expect that to write in the
"file # comment" file.
sed 's/x/y/#comment'
could break sed implementations that have # as a s flag as an
extension (not that I know of any).
--
Stephane
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.