Discussion:
Is it fair to say, "sed supports # comments starting any column"?
dgoldman@ehdp.com [sed-users]
2015-08-11 06:53:11 UTC
Permalink
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".


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?


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?


3) Given POSIX, is it fair to say, "sed supports # comments starting any column"?


4) What other standard overrides POSIX, and justifies other seds not getting "fixed up"?


Thanks,
Daniel




[Non-text portions of this message have been removed]
Rakesh Sharma sharma__r@hotmail.com [sed-users]
2015-08-11 07:23:30 UTC
Permalink
I normally use the ";#" syntax to start comments. The semicolon would start a newline and the # would then start at the first column, thus satisfying both.
Post by ***@ehdp.com [sed-users]
s/x/y/ # Silly comment 1
s/x/y/ ;# Silly comment 1

________________________________
From: sed-***@yahoogroups.com <sed-***@yahoogroups.com> on behalf of ***@ehdp.com [sed-users] <sed-***@yahoogroups.com>
Sent: Monday, August 10, 2015 11:53 PM
To: sed-***@yahoogroups.com
Subject: Is it fair to say, "sed supports # comments starting any column"?



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".


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?


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?


3) Given POSIX, is it fair to say, "sed supports # comments starting any column"?


4) What other standard overrides POSIX, and justifies other seds not getting "fixed up"?


Thanks,
Daniel



[Non-text portions of this message have been removed]





[Non-text portions of this message have been removed]
Daniel Goldman dgoldman@ehdp.com [sed-users]
2015-08-11 07:43:31 UTC
Permalink
Hi Rakesh,

I know you are trying to help. But you didn't answer any of my
questions. :( I am not a newbie trying to learn sed. I have specific
questions I am looking for experts such as yourself to weigh in on.

You are probably aware that some sed versions do not support ; syntax.
Plus, the POSIX standard does not mention ; syntax. So offering ; as a
solution doesn't help anyway.

Personally, I think it is fair to say, "sed supports # comments starting
any column", since that is what POSIX says. I am looking for someone to
explain why that is not true.

Thanks,
Daniel
Post by Rakesh Sharma ***@hotmail.com [sed-users]
I normally use the ";#" syntax to start comments. The semicolon would start a newline and the # would then start at the first column, thus satisfying both.
Post by ***@ehdp.com [sed-users]
s/x/y/ # Silly comment 1
s/x/y/ ;# Silly comment 1
________________________________
sharma__r@hotmail.com [sed-users]
2015-08-11 08:35:20 UTC
Permalink
Hi Daniel,

The POSIX spec does talk about the <semicolon> syntax, although it's not enforced.


The System V "sed" has this restriction that only the 1st line can be a
comment line, and then only if the first char. is #. (with #n as exception)


As to why some SEDs are not POSIX compliant in terms of the comment char I am not sure. Many times, things are a relic of the past when memory was at a premium & the sed versions may never have gotten upgraded.


Thanks,
Rakesh


---In sed-***@yahoogroups.com, <***@...> wrote :

Hi Rakesh,

I know you are trying to help. But you didn't answer any of my
questions. :( I am not a newbie trying to learn sed. I have specific
questions I am looking for experts such as yourself to weigh in on.

You are probably aware that some sed versions do not support ; syntax.
Plus, the POSIX standard does not mention ; syntax. So offering ; as a
solution doesn't help anyway.

Personally, I think it is fair to say, "sed supports # comments starting
any column", since that is what POSIX says. I am looking for someone to
explain why that is not true.

Thanks,
Daniel
Post by Rakesh Sharma ***@hotmail.com [sed-users]
I normally use the ";#" syntax to start comments. The semicolon would start a newline and the # would then start at the first column, thus satisfying both.
Post by ***@ehdp.com [sed-users]
s/x/y/ # Silly comment 1
s/x/y/ ;# Silly comment 1
________________________________
[Non-text portions of this message have been removed]
Daniel Goldman dgoldman@ehdp.com [sed-users]
2015-08-11 18:12:42 UTC
Permalink
Thanks. I didn't see where the POSIX spec talked about ; syntax. It
seems it should, because ; seems very useful. Just didn't see it. And of
course my post was not about ; syntax, that's a different issue.

Consistent with what you said, POSIX says, "The treatment of '#'
comments differs from the SVID which only allows a comment as the first
line of the script, but matches BSD-derived implementations. The comment
character is treated as a command, and it has the same properties in
terms of being accepted with leading <blank> characters; the BSD
implementation has historically supported this.". But it also says for #
definition, "Ignore the '#' and the remainder of the line". In other
words, the standard is to allow comments starting any column.

My questions #1 and #2 are at least partially answered, so that's a
little progress. But if this is it, that's disappointing. Anybody else?
Post by ***@hotmail.com [sed-users]
Hi Daniel,
The POSIX spec does talk about the <semicolon> syntax, although it's not enforced.
The System V "sed" has this restriction that only the 1st line can be a
comment line, and then only if the first char. is #. (with #n as exception)
As to why some SEDs are not POSIX compliant in terms of the comment char I am not sure. Many times, things are a relic of the past when memory was at a premium & the sed versions may never have gotten upgraded.
Thanks,
Rakesh
Hi Rakesh,
I know you are trying to help. But you didn't answer any of my
questions. :( I am not a newbie trying to learn sed. I have specific
questions I am looking for experts such as yourself to weigh in on.
You are probably aware that some sed versions do not support ; syntax.
Plus, the POSIX standard does not mention ; syntax. So offering ; as a
solution doesn't help anyway.
Personally, I think it is fair to say, "sed supports # comments starting
any column", since that is what POSIX says. I am looking for someone to
explain why that is not true.
Thanks,
Daniel
Post by Rakesh Sharma ***@hotmail.com [sed-users]
I normally use the ";#" syntax to start comments. The semicolon would start a newline and the # would then start at the first column, thus satisfying both.
Post by ***@ehdp.com [sed-users]
s/x/y/ # Silly comment 1
s/x/y/ ;# Silly comment 1
________________________________
[Non-text portions of this message have been removed]
------------------------------------
------------------------------------
Daniel Goldman dgoldman@ehdp.com [sed-users]
2015-08-12 05:37:42 UTC
Permalink
Hi Stephane,

Thanks for your thoughtful reply.

- The POSIX spec, at the link I sent, does not say "# is a command". If
anyone has a POSIX link with that wording, please post it. Instead,
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html says,
"The comment character is treated as a command, and it has the same
properties in terms of being accepted with leading <blank> characters".
The point is that # can have leading blanks.

The POSIX text is confusingly worded. What else is new? Even the GNU sed
manual sloppily lumps in # with other "commands". But a comment is not a
command. It's a comment. A command must be separated from other
commands. Neither POSIX nor the GNU sed manual say anything about having
to separate # from other commands on the same line. But I am open to
other information anyone might provide.

- The POSIX spec, at the link I sent, does not say "it (#) must be
separated from another command with ; or newline". If anyone has a
reference that says what you quoted, please post it. I think the
standard allows "s/x/y/ # comment" format.

- The POSIX spec, at the link I sent, does not mention ; syntax. If
anyone has a POSIX link that mentions ; syntax, please post it. I'm not
saying you are wrong. I would very much hope that POSIX would mention
the very useful ; syntax! If it does not, could it please by added? I
just don't see the mention, so the point about "s/x/y/; # comment" being
required does not make sense.

For some of the examples you post, probably best for me not to respond
unless someone can post the apparently different POSIX citation that
backs up the wordings you quote. You obviously have expertise with POSIX
specs. I hope you can provide a better link.

Could you clarify what you concluded about the solaris sed versions? I'm
not sure what "command -p" does.

Thanks for posting to the POSIX discussion group. My understanding of
your post and the replies is that solaris will at least be updated to
allow blanks before the # character, and that the intention is that it
be POSIX compliant, whatever that means. I think "s/x/y/ # comment" is
POSIX compliant. Does anyone disagree, and if so, on what basis?

Is my understanding correct, based on "SVID which only allows a comment
as the first line of the script", and what Rakesh said, that System V
only allows the line 1 of the script to be a comment? If so, isn't that
incredibly pitiful, and no basis for any kind of argument? It seems
extremely primitive, which is saying a lot coming from a seder. :)

AFAIK, the examples with the w command have nothing to do with this
comment issue, as exactly the same problem occurs with other sed syntax.
In other words, the w command has to end a script line, regardless of
what follows. Even ; after the w command will cause an error (assuming
the file name does not contain ; character).

You are right that # is not an s flag. It never will be, that would
break backward compatibility, not to speak of being an awful design
choice. Of course, sed 's/x/y/#comment' is asking for trouble, a kind of
"coding horror". But it is perfectly legal, and in accord with the POSIX
standard, to my understanding. And from your answer, it sounds like
there is no other standard that overrides POSIX.

The GNU sed online manual does not list "comments can start in any
column" as an GNU extension. Apparently, the maintainers consider GNU
sed # behavior to be POSIX compliant. To me, combined with the POSIX
wording I have seen so far, that indicates the answer to my question,
"is it fair to say sed supports # comments starting any column?" is
"YES". Would anyone argue "NO", and on what basis?

To my knowledge, 99% to 100% of languages do not require a command
separator before a comment. To me, the idea is ridiculous. The POSIX
standard is confusingly worded. But I doubt 100% that the POSIX
designers intended to require "s/x/y/; # comment". What would be the
point? I've used sed for decades, and the idea of "s/x/y/; # comment" is
laughable, even if POSIX mentioned ; syntax. As you point out, "fixing"
a sed version to allow "s/x/y/ # comment" would not break existing
scripts. In contrast, requiring "s/x/y/; # comment" syntax would break
scripts. :( Thus, my answer to "must sed # comments be separated from
commands on the same line by ; syntax?" is "NO". Would anyone argue
"YES", and on what basis?

Thanks,
Daniel
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).
Post by ***@ehdp.com [sed-users]
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
1) Which actively maintained sed versions require comments to start in column 1?
s11:~$ echo x | sed ' #'
x
s11:~$ echo x | command -p sed ' #'
sed: # is an unrecognized command.
s11:(2)~$ echo x | command -p sed '#'
x
Post by ***@ehdp.com [sed-users]
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.
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.
Post by ***@ehdp.com [sed-users]
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.
Post by ***@ehdp.com [sed-users]
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).
Tim Chase sed@thechases.com [sed-users]
2015-08-12 12:08:30 UTC
Permalink
Post by Daniel Goldman ***@ehdp.com [sed-users]
- The POSIX spec, at the link I sent, does not say "# is a
command". If anyone has a POSIX link with that wording, please post
it. Instead,
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
says, "The comment character is treated as a command, and it has
the same properties in terms of being accepted with leading <blank>
characters". The point is that # can have leading blanks.
The POSIX text is confusingly worded. What else is new? Even the
GNU sed manual sloppily lumps in # with other "commands". But a
comment is not a command. It's a comment.
Well, that link does lump "#" in with other commands:

"""
Command verbs other than {, a, b, c, i, r, t, w, :, and # can be
followed by a <semicolon>, optional <blank> characters, and another
command verb.
"""

so it seems to be pretty clearly indicating that "#" is a "command
verb" on par with other command-verbs, even if that command's effect
is "ignore to the EOL".

And to back that up, the definition of "#" is listed under the
"Editing commands in sed" section, not some "other syntactic elements
that are not commands".
Post by Daniel Goldman ***@ehdp.com [sed-users]
- The POSIX spec, at the link I sent, does not say "it (#) must be
separated from another command with ; or newline". If anyone has a
reference that says what you quoted, please post it. I think the
standard allows "s/x/y/ # comment" format.
But when you read that "#" is considered a command, then the
guideline that commands be separated by semicolons is implied.
Post by Daniel Goldman ***@ehdp.com [sed-users]
- The POSIX spec, at the link I sent, does not mention ; syntax. If
anyone has a POSIX link that mentions ; syntax, please post it.
I quoted the semicolon syntax from the link you gave.
Post by Daniel Goldman ***@ehdp.com [sed-users]
Thanks for posting to the POSIX discussion group. My understanding
of your post and the replies is that solaris will at least be
updated to allow blanks before the # character, and that the
intention is that it be POSIX compliant, whatever that means. I
think "s/x/y/ # comment" is POSIX compliant. Does anyone disagree,
and if so, on what basis?
See the quote above. "#" is a command, and when chaining commands, it
requires a ";"
Post by Daniel Goldman ***@ehdp.com [sed-users]
Is my understanding correct, based on "SVID which only allows a
comment as the first line of the script", and what Rakesh said,
that System V only allows the line 1 of the script to be a comment?
If so, isn't that incredibly pitiful, and no basis for any kind of
argument? It seems extremely primitive, which is saying a lot
coming from a seder. :)
Quoting that linked spec

"""
The requirements for acceptance of <blank> and <space> characters in
command lines has been made more explicit than in early proposals to
describe clearly the historical practice and to remove confusion
about the phrase "protect initial blanks [sic] and tabs from the
stripping that is done on every script line" that appears in much of
the historical documentation of the sed utility description of text.
(Not all implementations are known to have stripped <blank>
characters from text lines, although they all have allowed leading
<blank> characters preceding the address on a command line.)

The treatment of '#' comments differs from the SVID which only allows
a comment as the first line of the script, but matches BSD-derived
implementations. The comment character is treated as a command, and
it has the same properties in terms of being accepted with leading
<blank> characters; the BSD implementation has historically supported
this.
"""

So my reading is that modern compliant implementations must allow for
leading blanks, but that historical implementations can require
the comment char to begin in the first column.
Post by Daniel Goldman ***@ehdp.com [sed-users]
The GNU sed online manual does not list "comments can start in any
column" as an GNU extension. Apparently, the maintainers consider
GNU sed # behavior to be POSIX compliant. To me, combined with the
POSIX wording I have seen so far, that indicates the answer to my
question, "is it fair to say sed supports # comments starting any
column?" is "YES". Would anyone argue "NO", and on what basis?
As above, the only acceptable "NO" would be "I'm a[n] historical
implementation".
Post by Daniel Goldman ***@ehdp.com [sed-users]
To my knowledge, 99% to 100% of languages do not require a command
separator before a comment.
Welcome to one of the ones that does. Like some BASICs and .bat
files where REM is treated as a command and thus must come in a
command context.
Post by Daniel Goldman ***@ehdp.com [sed-users]
Thus, my answer to "must sed # comments be separated from commands
on the same line by ; syntax?" is "NO". Would anyone argue "YES",
and on what basis?
I would argue that technically it must be because the spec treats "#"
as a command and thus it requires a command-separator. GNU sed
appears to relax that requirement and allow a comment to start after
a non-consume-to-end-of-line command.

-tim
Aurelio Jargas verde@aurelio.net [sed-users]
2015-08-12 10:43:44 UTC
Permalink
To add a new data point to the discussion:


$ echo a | sed 'p #foo'
sed: 1: "p #foo": extra characters at the end of p command


$ echo a | sed 's/a/b/ #foo'
sed: 1: "s/a/b/ #foo": bad flag in substitute command: '#'


That's on a recent Mac (OS X 10.10.3, BSD sed). I couldn't find the
specific sed version since it doesn't have --version neither -V.


From the manual page:


The sed utility is expected to be a superset of the IEEE Std 1003.2
(``POSIX.2'') specification.
Post by Daniel Goldman ***@ehdp.com [sed-users]
Hi Stephane,
Thanks for your thoughtful reply.
- The POSIX spec, at the link I sent, does not say "# is a command". If
anyone has a POSIX link with that wording, please post it. Instead,
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html says,
"The comment character is treated as a command, and it has the same
properties in terms of being accepted with leading <blank> characters".
The point is that # can have leading blanks.
The POSIX text is confusingly worded. What else is new? Even the GNU sed
manual sloppily lumps in # with other "commands". But a comment is not a
command. It's a comment. A command must be separated from other
commands. Neither POSIX nor the GNU sed manual say anything about having
to separate # from other commands on the same line. But I am open to
other information anyone might provide.
- The POSIX spec, at the link I sent, does not say "it (#) must be
separated from another command with ; or newline". If anyone has a
reference that says what you quoted, please post it. I think the
standard allows "s/x/y/ # comment" format.
- The POSIX spec, at the link I sent, does not mention ; syntax. If
anyone has a POSIX link that mentions ; syntax, please post it. I'm not
saying you are wrong. I would very much hope that POSIX would mention
the very useful ; syntax! If it does not, could it please by added? I
just don't see the mention, so the point about "s/x/y/; # comment" being
required does not make sense.
For some of the examples you post, probably best for me not to respond
unless someone can post the apparently different POSIX citation that
backs up the wordings you quote. You obviously have expertise with POSIX
specs. I hope you can provide a better link.
Could you clarify what you concluded about the solaris sed versions? I'm
not sure what "command -p" does.
Thanks for posting to the POSIX discussion group. My understanding of
your post and the replies is that solaris will at least be updated to
allow blanks before the # character, and that the intention is that it
be POSIX compliant, whatever that means. I think "s/x/y/ # comment" is
POSIX compliant. Does anyone disagree, and if so, on what basis?
Is my understanding correct, based on "SVID which only allows a comment
as the first line of the script", and what Rakesh said, that System V
only allows the line 1 of the script to be a comment? If so, isn't that
incredibly pitiful, and no basis for any kind of argument? It seems
extremely primitive, which is saying a lot coming from a seder. :)
AFAIK, the examples with the w command have nothing to do with this
comment issue, as exactly the same problem occurs with other sed syntax.
In other words, the w command has to end a script line, regardless of
what follows. Even ; after the w command will cause an error (assuming
the file name does not contain ; character).
You are right that # is not an s flag. It never will be, that would
break backward compatibility, not to speak of being an awful design
choice. Of course, sed 's/x/y/#comment' is asking for trouble, a kind of
"coding horror". But it is perfectly legal, and in accord with the POSIX
standard, to my understanding. And from your answer, it sounds like
there is no other standard that overrides POSIX.
The GNU sed online manual does not list "comments can start in any
column" as an GNU extension. Apparently, the maintainers consider GNU
sed # behavior to be POSIX compliant. To me, combined with the POSIX
wording I have seen so far, that indicates the answer to my question,
"is it fair to say sed supports # comments starting any column?" is
"YES". Would anyone argue "NO", and on what basis?
To my knowledge, 99% to 100% of languages do not require a command
separator before a comment. To me, the idea is ridiculous. The POSIX
standard is confusingly worded. But I doubt 100% that the POSIX
designers intended to require "s/x/y/; # comment". What would be the
point? I've used sed for decades, and the idea of "s/x/y/; # comment" is
laughable, even if POSIX mentioned ; syntax. As you point out, "fixing"
a sed version to allow "s/x/y/ # comment" would not break existing
scripts. In contrast, requiring "s/x/y/; # comment" syntax would break
scripts. :( Thus, my answer to "must sed # comments be separated from
commands on the same line by ; syntax?" is "NO". Would anyone argue
"YES", and on what basis?
Thanks,
Daniel
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).
Post by ***@ehdp.com [sed-users]
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
Post by ***@ehdp.com [sed-users]
1) Which actively maintained sed versions require comments to start
in column 1?
s11:~$ echo x | sed ' #'
x
s11:~$ echo x | command -p sed ' #'
sed: # is an unrecognized command.
s11:(2)~$ echo x | command -p sed '#'
x
Post by ***@ehdp.com [sed-users]
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.
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.
Post by ***@ehdp.com [sed-users]
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.
Post by ***@ehdp.com [sed-users]
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).
------------------------------------
------------------------------------
--
------------------------------------
Yahoo Groups Links
--
Aurelio | www.aurelio.net | @oreio




[Non-text portions of this message have been removed]
Stephane Chazelas stephane.chazelas@gmail.com [sed-users]
2015-08-12 10:27:23 UTC
Permalink
Post by Daniel Goldman ***@ehdp.com [sed-users]
Hi Stephane,
Thanks for your thoughtful reply.
- The POSIX spec, at the link I sent, does not say "# is a command".
The POSIX spec for sed is a total mess IMO. It leaves plenty of
things unspecified. It specifies idiosyncraties of early
implementations instead of leaving the behaviour unspecified
(like !! is to be the same as !), it requires things that no sed
implementations ever required.


However it does say "#" is a command verb and is listed among
the other command verbs.


It does say the semicolon can be used to separate commands and
it does say blanks are allowed around addresses.
Post by Daniel Goldman ***@ehdp.com [sed-users]
The POSIX text is confusingly worded. What else is new? Even the GNU sed
manual sloppily lumps in # with other "commands".
Except for the b/t/: commands, it's allowed to do that as it's
unspecified in POSIX.
Post by Daniel Goldman ***@ehdp.com [sed-users]
But a comment is not a
command. It's a comment. A command must be separated from other
commands. Neither POSIX nor the GNU sed manual say anything about having
to separate # from other commands on the same line. But I am open to
other information anyone might provide.
It is a command in the POSIX spec. GNU sed doesn't treat it as a
command. It's OK to do that as long as it's not otherwise
breaking conformance.


g # foo


is OK. g doesn't take arguments, so if you write "g # foo" in
your script, your script is not a POSIX conformant script, so
returning an error or ignoring that "# foo" are two conforming
behaviours as it's not specified.
Post by Daniel Goldman ***@ehdp.com [sed-users]
- The POSIX spec, at the link I sent, does not say "it (#) must be
separated from another command with ; or newline".
It does say a command other than a few can be followed by
semicolon followed by another command (# being no exception).
Post by Daniel Goldman ***@ehdp.com [sed-users]
I think the standard allows "s/x/y/ # comment" format.
That is left unspecified. If you do "s/x/y/ # comment", you have
no guarantee of the outcome, that " # comment" could be ignored,
or you can get an error, or "#" could be treated as a s flag as
an extension.
Post by Daniel Goldman ***@ehdp.com [sed-users]
- The POSIX spec, at the link I sent, does not mention ; syntax. If
anyone has a POSIX link that mentions ; syntax, please post it. I'm not
saying you are wrong. I would very much hope that POSIX would mention
the very useful ; syntax! If it does not, could it please by added? I
just don't see the mention, so the point about "s/x/y/; # comment" being
required does not make sense.
Read the spec you posted again, and search for "semicolon"
Post by Daniel Goldman ***@ehdp.com [sed-users]
For some of the examples you post, probably best for me not to respond
unless someone can post the apparently different POSIX citation that
backs up the wordings you quote. You obviously have expertise with POSIX
specs. I hope you can provide a better link.
Could you clarify what you concluded about the solaris sed versions? I'm
not sure what "command -p" does.
I conclude that Solaris is not compliant. "command -p cmd" is
meant to invoke the POSIX (portable) version of cmd. In the case
of Solaris, that's /usr/xpg4/bin/sed.


[...]
Post by Daniel Goldman ***@ehdp.com [sed-users]
Is my understanding correct, based on "SVID which only allows a comment
as the first line of the script", and what Rakesh said, that System V
only allows the line 1 of the script to be a comment? If so, isn't that
incredibly pitiful, and no basis for any kind of argument? It seems
extremely primitive, which is saying a lot coming from a seder. :)
[...]


That was specifying the behaviour at the time (80s). It was
saying that you shouldn't write sed ' # comment' because SysV
sed implementations didn't support it. It was not preventing
conforming sed implementations from supporting it.


I don't expect any modern system would follow that standard (at
least not on the aspect where it's not compatible with POSIX (if
any)).
Post by Daniel Goldman ***@ehdp.com [sed-users]
AFAIK, the examples with the w command have nothing to do with this
comment issue, as exactly the same problem occurs with other sed syntax.
In other words, the w command has to end a script line, regardless of
what follows. Even ; after the w command will cause an error (assuming
the file name does not contain ; character).
It's relevant is that when you ask: "can a comment start in any
column?", the answer is no because in:


#! /usr/bin/sed -f
w some # long\
# file with newline


"#" doesn't start a comment but is considered as part of the
file name. In my understanding, that's meant to write to the
"some # long<newline># file with newline" file (so GNU sed is
not compliant here as it writes to "some # long\" instead,
though that's not a big issue as there's little chance anyone
would want to do that).
Post by Daniel Goldman ***@ehdp.com [sed-users]
You are right that # is not an s flag. It never will be, that would
break backward compatibility
That would not break POSIX sed scripts. That may break some
scripts that rely on the specific behaviour of GNU sed to accept
comments anywhere.
Post by Daniel Goldman ***@ehdp.com [sed-users]
choice. Of course, sed 's/x/y/#comment' is asking for trouble, a kind of
"coding horror". But it is perfectly legal, and in accord with the POSIX
standard, to my understanding.
No, AFAICT, there's nothing in the POSIX spec that specifies
what the effect of s/x/y/#comment is.
Post by Daniel Goldman ***@ehdp.com [sed-users]
And from your answer, it sounds like
there is no other standard that overrides POSIX.
There are standards that systems may want to follow that
override or complement POSIX (like the Debian policy, the Linux
Standard Base, options XSI (Unix) in the Single Unix
Specification beyond the base). I meant that I was not aware of
a standard that would disagree with POSIX on this.
Post by Daniel Goldman ***@ehdp.com [sed-users]
The GNU sed online manual does not list "comments can start in any
column" as an GNU extension. Apparently, the maintainers consider GNU
sed # behavior to be POSIX compliant. To me, combined with the POSIX
wording I have seen so far, that indicates the answer to my question,
"is it fair to say sed supports # comments starting any column?" is
"YES". Would anyone argue "NO", and on what basis?
No, as said already


w blah # blah


doesn't start a comment even in GNU sed.
Post by Daniel Goldman ***@ehdp.com [sed-users]
To my knowledge, 99% to 100% of languages do not require a command
separator before a comment. To me, the idea is ridiculous. The POSIX
standard is confusingly worded. But I doubt 100% that the POSIX
designers intended to require "s/x/y/; # comment". What would be the
point?
POSIX is a standard to help write portable applications. In the
early days at least, it was descriptive (it's now becoming more
prescriptive). The specification was specifying what you could
and could not do for your script to be portable to the different
compliant implementations around. And that's how sed (which
predates most other languages that have # as a comment) was
implemented.
Post by Daniel Goldman ***@ehdp.com [sed-users]
I've used sed for decades, and the idea of "s/x/y/; # comment" is
laughable, even if POSIX mentioned ; syntax.
It may be laughable, but it will break with many (most) sed
implementations including the ones directly derived from the
original implementation and others that don't like FreeBSD's if
you use s/x/y/ # comment.
Post by Daniel Goldman ***@ehdp.com [sed-users]
As you point out, "fixing"
a sed version to allow "s/x/y/ # comment" would not break existing
scripts. In contrast, requiring "s/x/y/; # comment" syntax would break
scripts. :( Thus, my answer to "must sed # comments be separated from
commands on the same line by ; syntax?" is "NO". Would anyone argue
"YES", and on what basis?
YES, because many sed implementations will fail otherwise and
they are allowed to by POSIX.


The joy of writing portable script is having to deal with all
the idiosyncraties of the various implementations. POSIX is a
great tool to tell you what you may or may not do. In the case
of sed though, I'd agree the POSIX spec is "sub-standard" (pun
intended).
--
Stephane
Loading...