www.delorie.com/gnu/docs/sed/sed_33.html   search  
 
Buy the book!


sed, a stream editor

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

7. Reporting Bugs

Email bug reports to bonzini@gnu.org. Be sure to include the word "sed" somewhere in the Subject: field. Also, please include the output of `sed --version' in the body of your report if at all possible.

Please do not send a bug report like this:

 
while building frobme-1.3.4
$ configure 
error--> sed: file sedscr line 1: Unknown option to 's'

If GNU sed doesn't configure your favorite package, take a few extra minutes to identify the specific problem and make a stand-alone test case. Unlike other programs such as C compilers, making such test cases for sed is quite simple.

A stand-alone test case includes all the data necessary to perform the test, and the specific invocation of sed that causes the problem. The smaller a stand-alone test case is, the better. A test case should not involve something as far removed from sed as "try to configure frobme-1.3.4". Yes, that is in principle enough information to look for the bug, but that is not a very practical prospect.

Here are a few commonly reported bugs that are not bugs.

`sed -n' and `s/regex/`replace'/p'
Some versions of sed ignore the p (print) option of an s command unless the `-n' command-line option has been specified. Other versions always honor the p option. Both approaches are allowed by POSIX and GNU sed is the better when you write complex scripts and also more intuitive, but portable scripts should be written to work correctly with either behavior.

N command on the last line

Most versions of sed exit without printing anything when the N command is issued on the last line of a file. GNU sed prints pattern space before exiting unless of course the -n command switch has been specified. This choice is by design.

For example, the behavior of
 
sed N foo bar
would depend on whether foo has an even or an odd number of lines(9). Or, when writing a script to read the next few lines following a pattern match, traditional implementations of sed would force you to write something like
 
/foo/{ $!N; $!N; $!N; $!N; $!N; $!N; $!N; $!N; $!N }
instead of just
 
/foo/{ N;N;N;N;N;N;N;N;N; }
In any case, the simplest workaround is to use $d;N in scripts that rely on the traditional behavior.

Regex syntax clashes
sed uses the POSIX basic regular expression syntax. According to the standard, the meaning of some escape sequences is undefined in this syntax; notable in the case of sed are \|, \+, \?, \`, \', \<, \>, \b, \B, \w, and \W.

As in all GNU programs that use POSIX basic regular expressions, sed interprets these escape sequences as meta-characters. So, x\+ matches one or more occurrences of `x'. abc\|def matches either `abc' or `def'.

This syntax may cause problems when running scripts written for other seds. Some sed programs have been written with the assumption that \| and \+ match the literal characters | and +. Such scripts must be modified by removing the spurious backslashes if they are to be used with modern implementations of sed, like GNU sed.

In addition, this version of sed supports several escape characters (some of which are multi-character) to insert non-printable characters in scripts (\a, \c, \d, \o, \r, \t, \v, \x). These can cause similar problems with scripts written for other seds.

`-i' clobbers read-only files

In short, `sed -i' will let you delete the contents of a read-only file, and in general the `-i' option (see section Invocation) lets you clobber protected files. This is not a bug, but rather a consequence of how the Unix filesystem works.

The permissions on a file say what can happen to the data in that file, while the permissions on a directory say what can happen to the list of files in that directory. `sed -i' will not ever open for writing a file that is already on disk. Rather, it will work on a temporary file that is finally renamed to the original name: if you rename or delete files, you're actually modifying the contents of the directory, so the operation depends on the permissions of the directory, not of the file. For this same reason, sed does not let you use `-i' on a writeable file in a read-only directory (but unbelievably nobody reports that as a bug...).


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright © 2003   by The Free Software Foundation     Updated Jun 2003