"sed" question - undocumented features like comments
Guy Harris
guy at sun.uucp
Wed Nov 20 11:20:55 AEST 1985
> Gee, I tried running a script with multiple lines of comments sprinkled
> throughout it on the 4.2 and S5 "sed"s and they both worked exactly the
> same... First *line*? I don't believe anybody'd be so sloppy as to require
> all comments to fit into *one* line.
I checked up on it and -- good grief, they *were* that sloppy. It turns out
that the S5 "sed" we're running here has the Berkeley comment code stuck in.
The change is trivial; change line 171 of "sed0.c" (or thereabouts; it's
line 171 in the S5R2V1 VAX distribution) from
if(*cp == '\0') continue;
to
if(*cp == '\0' || *cp == '#') continue;
Your line numbers may differ on V7, S3, other S5's, etc..
Note that 1) if you continue a command on multiple lines using \, "#" at the
beginning of those continuation lines will NOT be treated as a comment
indicator, and 2) "#" in the middle of a command (i.e., not at the beginning
of a line or separated from the beginning of the line only by whitespace)
will also not be treated as a comment indicator. This is a feature; it
means that old scripts won't break by virtue of "#" characters which used to
be legitimate parts of commands suddenly becoming comments....
Also note that, even in "sed"s without this code, you shouldn't have the
first line of a script be a comment which immediately follows the "#" and
begins with a lower-case "n" unless you want the script always to be run as
if "sed" had been invoked with the "-n" flag. If the first two characters
of a script are "#n", it turns on the "-n" flag, as mentioned before...
Guy Harris
More information about the Comp.bugs.2bsd
mailing list