596 lines
24 KiB
HTML
596 lines
24 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>diff</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="diff"></a> <a name="tag_04_37"></a><!-- diff -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_04_37_01"></a>NAME</h4>
|
|
|
|
<blockquote>diff - compare two files</blockquote>
|
|
|
|
<h4><a name="tag_04_37_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>diff</tt> <b>[</b><tt>-c| -e| -f| -C</tt> <i>n</i><b>][</b><tt>-br</tt><b>]</b> <i>file1 file2</i></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>diff</i> utility shall compare the contents of <i>file1</i> and <i>file2</i> and write to standard output a list of
|
|
changes necessary to convert <i>file1</i> into <i>file2</i>. This list should be minimal. No output shall be produced if the files
|
|
are identical.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_04"></a>OPTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>diff</i> utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p>
|
|
|
|
<p>The following options shall be supported:</p>
|
|
|
|
<dl compact>
|
|
<dt><b>-b</b></dt>
|
|
|
|
<dd>Cause any amount of white space at the end of a line to be treated as a single <newline> (that is, the white-space
|
|
characters preceding the <newline> are ignored) and other strings of white-space characters, not including <newline>s,
|
|
to compare equal.</dd>
|
|
|
|
<dt><b>-c</b></dt>
|
|
|
|
<dd>Produce output in a form that provides three lines of context.</dd>
|
|
|
|
<dt><b>-C n</b></dt>
|
|
|
|
<dd>Produce output in a form that provides <i>n</i> lines of context (where <i>n</i> shall be interpreted as a positive decimal
|
|
integer).</dd>
|
|
|
|
<dt><b>-e</b></dt>
|
|
|
|
<dd>Produce output in a form suitable as input for the <a href="../utilities/ed.html"><i>ed</i></a> utility, which can then be used
|
|
to convert <i>file1</i> into <i>file2</i>.</dd>
|
|
|
|
<dt><b>-f</b></dt>
|
|
|
|
<dd>Produce output in an alternative form, similar in format to <b>-e</b>, but not intended to be suitable as input for the <a
|
|
href="../utilities/ed.html"><i>ed</i></a> utility, and in the opposite order.</dd>
|
|
|
|
<dt><b>-r</b></dt>
|
|
|
|
<dd>Apply <i>diff</i> recursively to files and directories of the same name when <i>file1</i> and <i>file2</i> are both
|
|
directories.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_05"></a>OPERANDS</h4>
|
|
|
|
<blockquote>
|
|
<p>The following operands shall be supported:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>file1</i>, <i>file2</i></dt>
|
|
|
|
<dd>A pathname of a file to be compared. If either the <i>file1</i> or <i>file2</i> operand is <tt>'-'</tt> , the standard input
|
|
shall be used in its place.</dd>
|
|
</dl>
|
|
|
|
<p>If both <i>file1</i> and <i>file2</i> are directories, <i>diff</i> shall not compare block special files, character special
|
|
files, or FIFO special files to any files and shall not compare regular files to directories. Further details are as specified in
|
|
<a href="#tag_04_37_10_01">Diff Directory Comparison Format</a> . The behavior of <i>diff</i> on other file types is
|
|
implementation-defined when found in directories.</p>
|
|
|
|
<p>If only one of <i>file1</i> and <i>file2</i> is a directory, <i>diff</i> shall be applied to the non-directory file and the file
|
|
contained in the directory file with a filename that is the same as the last component of the non-directory file.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_06"></a>STDIN</h4>
|
|
|
|
<blockquote>
|
|
<p>The standard input shall be used only if one of the <i>file1</i> or <i>file2</i> operands references standard input. See the
|
|
INPUT FILES section.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_07"></a>INPUT FILES</h4>
|
|
|
|
<blockquote>
|
|
<p>The input files may be of any type.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_08"></a>ENVIRONMENT VARIABLES</h4>
|
|
|
|
<blockquote>
|
|
<p>The following environment variables shall affect the execution of <i>diff</i>:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>LANG</i></dt>
|
|
|
|
<dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
|
|
the precedence of internationalization variables used to determine the values of locale categories.)</dd>
|
|
|
|
<dt><i>LC_ALL</i></dt>
|
|
|
|
<dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
|
|
|
|
<dt><i>LC_CTYPE</i></dt>
|
|
|
|
<dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
|
|
opposed to multi-byte characters in arguments and input files).</dd>
|
|
|
|
<dt><i>LC_MESSAGES</i></dt>
|
|
|
|
<dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and
|
|
informative messages written to standard output.</dd>
|
|
|
|
<dt><i>LC_TIME</i></dt>
|
|
|
|
<dd>Determine the locale for affecting the format of file timestamps written with the <b>-C</b> and <b>-c</b> options.</dd>
|
|
|
|
<dt><i>NLSPATH</i></dt>
|
|
|
|
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"></dd>
|
|
|
|
<dt><i>TZ</i></dt>
|
|
|
|
<dd>Determine the timezone used for calculating file timestamps written with the <b>-C</b> and <b>-c</b> options. If <i>TZ</i> is
|
|
unset or null, an unspecified default timezone shall be used.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_09"></a>ASYNCHRONOUS EVENTS</h4>
|
|
|
|
<blockquote>
|
|
<p>Default.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_10"></a>STDOUT</h4>
|
|
|
|
<blockquote>
|
|
<h5><a name="tag_04_37_10_01"></a>Diff Directory Comparison Format</h5>
|
|
|
|
<p>If both <i>file1</i> and <i>file2</i> are directories, the following output formats shall be used.</p>
|
|
|
|
<p>In the POSIX locale, each file that is present in only one directory shall be reported using the following format:</p>
|
|
|
|
<pre>
|
|
<tt>"Only in %s: %s\n", <</tt><i>directory pathname</i><tt>>, <</tt><i>filename</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>In the POSIX locale, subdirectories that are common to the two directories may be reported with the following format:</p>
|
|
|
|
<pre>
|
|
<tt>"Common subdirectories: %s and %s\n", <</tt><i>directory1 pathname</i><tt>>,
|
|
<</tt><i>directory2 pathname</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>For each file common to the two directories if the two files are not to be compared, the following format shall be used in the
|
|
POSIX locale:</p>
|
|
|
|
<pre>
|
|
<tt>"File %s is a %s while file %s is a %s\n", <</tt><i>directory1 pathname</i><tt>>,
|
|
<</tt><i>file type of directory1 pathname</i><tt>>, <</tt><i>directory2 pathname</i><tt>>,
|
|
<</tt><i>file type of directory2 pathname</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>For each file common to the two directories, if the files are compared and are identical, no output shall be written. If the two
|
|
files differ, the following format is written:</p>
|
|
|
|
<pre>
|
|
<tt>"diff %s %s %s\n", <</tt><i>diff_options</i><tt>>, <</tt><i>filename1</i><tt>>, <</tt><i>filename2</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>where <<i>diff_options</i>> are the options as specified on the command line.</p>
|
|
|
|
<p>All directory pathnames listed in this section shall be relative to the original command line arguments. All other names of
|
|
files listed in this section shall be filenames (pathname components).</p>
|
|
|
|
<h5><a name="tag_04_37_10_02"></a>Diff Binary Output Format</h5>
|
|
|
|
<p>In the POSIX locale, if one or both of the files being compared are not text files, an unspecified format shall be used that
|
|
contains the pathnames of two files being compared and the string <tt>"differ"</tt> .</p>
|
|
|
|
<p>If both files being compared are text files, depending on the options specified, one of the following formats shall be used to
|
|
write the differences.</p>
|
|
|
|
<h5><a name="tag_04_37_10_03"></a>Diff Default Output Format</h5>
|
|
|
|
<p>The default (without <b>-e</b>, <b>-f</b>, <b>-c</b>, or <b>-C</b> options) <i>diff</i> utility output shall contain lines of
|
|
these forms:</p>
|
|
|
|
<pre>
|
|
<tt>"%da%d\n", <</tt><i>num1</i><tt>>, <</tt><i>num2</i><tt>>
|
|
<br>
|
|
"%da%d,%d\n", <</tt><i>num1</i><tt>>, <</tt><i>num2</i><tt>>, <</tt><i>num3</i><tt>>
|
|
<br>
|
|
"%dd%d\n", <</tt><i>num1</i><tt>>, <</tt><i>num2</i><tt>>
|
|
<br>
|
|
"%d,%dd%d\n", <</tt><i>num1</i><tt>>, <</tt><i>num2</i><tt>>, <</tt><i>num3</i><tt>>
|
|
<br>
|
|
"%dc%d\n", <</tt><i>num1</i><tt>>, <</tt><i>num2</i><tt>>
|
|
<br>
|
|
"%d,%dc%d\n", <</tt><i>num1</i><tt>>, <</tt><i>num2</i><tt>>, <</tt><i>num3</i><tt>>
|
|
<br>
|
|
"%dc%d,%d\n", <</tt><i>num1</i><tt>>, <</tt><i>num2</i><tt>>, <</tt><i>num3</i><tt>>
|
|
<br>
|
|
"%d,%dc%d,%d\n", <</tt><i>num1</i><tt>>, <</tt><i>num2</i><tt>>, <</tt><i>num3</i><tt>>, <</tt><i>num4</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>These lines resemble <a href="../utilities/ed.html"><i>ed</i></a> subcommands to convert <i>file1</i> into <i>file2</i>. The
|
|
line numbers before the action letters shall pertain to <i>file1</i>; those after shall pertain to <i>file2</i>. Thus, by
|
|
exchanging <i>a</i> for <i>d</i> and reading the line in reverse order, one can also determine how to convert <i>file2</i> into
|
|
<i>file1</i>. As in <a href="../utilities/ed.html"><i>ed</i></a>, identical pairs (where <i>num1</i>= <i>num2</i>) are abbreviated
|
|
as a single number.</p>
|
|
|
|
<p>Following each of these lines, <i>diff</i> shall write to standard output all lines affected in the first file using the
|
|
format:</p>
|
|
|
|
<pre>
|
|
<tt>"<<img src="../images/delta.gif" border="0">%s", <</tt><i>line</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>and all lines affected in the second file using the format:</p>
|
|
|
|
<pre>
|
|
<tt>"><img src="../images/delta.gif" border="0">%s", <</tt><i>line</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>If there are lines affected in both <i>file1</i> and <i>file2</i> (as with the <b>c</b> subcommand), the changes are separated
|
|
with a line consisting of three hyphens:</p>
|
|
|
|
<pre>
|
|
<tt>"---\n"
|
|
</tt>
|
|
</pre>
|
|
|
|
<h5><a name="tag_04_37_10_04"></a>Diff -e Output Format</h5>
|
|
|
|
<p>With the <b>-e</b> option, a script shall be produced that shall, when provided as input to <a href=
|
|
"../utilities/ed.html"><i>ed</i></a>, along with an appended <b>w</b> (write) command, convert <i>file1</i> into <i>file2</i>. Only
|
|
the <b>a</b> (append), <b>c</b> (change), <b>d</b> (delete), <b>i</b> (insert), and <b>s</b> (substitute) commands of <a href=
|
|
"../utilities/ed.html"><i>ed</i></a> shall be used in this script. Text lines, except those consisting of the single character
|
|
period ( <tt>'.'</tt> ), shall be output as they appear in the file.</p>
|
|
|
|
<h5><a name="tag_04_37_10_05"></a>Diff -f Output Format</h5>
|
|
|
|
<p>With the <b>-f</b> option, an alternative format of script shall be produced. It is similar to that produced by <b>-e</b>, with
|
|
the following differences:</p>
|
|
|
|
<ol>
|
|
<li>
|
|
<p>It is expressed in reverse sequence; the output of <b>-e</b> orders changes from the end of the file to the beginning; the
|
|
<b>-f</b> from beginning to end.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The command form <<i>lines</i>> <<i>command-letter</i>> used by <b>-e</b> is reversed. For example, 10<i>c</i> with
|
|
<b>-e</b> would be <i>c</i>10 with <b>-f</b>.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The form used for ranges of line numbers is <space>-separated, rather than comma-separated.</p>
|
|
</li>
|
|
</ol>
|
|
|
|
<h5><a name="tag_04_37_10_06"></a>Diff -c or -C Output Format</h5>
|
|
|
|
<p>With the <b>-c</b> or <b>-C</b> option, the output format shall consist of affected lines along with surrounding lines of
|
|
context. The affected lines shall show which ones need to be deleted or changed in <i>file1</i>, and those added from <i>file2</i>.
|
|
With the <b>-c</b> option, three lines of context, if available, shall be written before and after the affected lines. With the
|
|
<b>-C</b> option, the user can specify how many lines of context are written. The exact format follows.</p>
|
|
|
|
<p>The name and last modification time of each file shall be output in the following format:</p>
|
|
|
|
<pre>
|
|
<tt>"*** %s %s\n",</tt> <i>file1</i><tt>, <</tt><i>file1 timestamp</i><tt>>
|
|
"--- %s %s\n",</tt> <i>file2</i><tt>, <</tt><i>file2 timestamp</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>Each <<i>file</i>> field shall be the pathname of the corresponding file being compared. The pathname written for standard
|
|
input is unspecified.</p>
|
|
|
|
<p>In the POSIX locale, each <<i>timestamp</i>> field shall be equivalent to the output from the following command:</p>
|
|
|
|
<pre>
|
|
<tt>date "+%a %b %e %T %Y"
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>without the trailing <newline>, executed at the time of last modification of the corresponding file (or the current time,
|
|
if the file is standard input).</p>
|
|
|
|
<p>Then, the following output formats shall be applied for every set of changes.</p>
|
|
|
|
<p>First, a line shall be written in the following format:</p>
|
|
|
|
<pre>
|
|
<tt>"***************\n"
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>Next, the range of lines in <i>file1</i> shall be written in the following format:</p>
|
|
|
|
<pre>
|
|
<tt>"*** %d,%d ****\n", <</tt><i>beginning line number</i><tt>>, <</tt><i>ending line number</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>Next, the affected lines along with lines of context (unaffected lines) shall be written. Unaffected lines shall be written in
|
|
the following format:</p>
|
|
|
|
<pre>
|
|
<tt>"<img src="../images/delta.gif" border="0"><img src="../images/delta.gif" border=
|
|
"0">%s", <</tt><i>unaffected_line</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>Deleted lines shall be written as:</p>
|
|
|
|
<pre>
|
|
<tt>"-<img src="../images/delta.gif" border="0">%s", <</tt><i>deleted_line</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>Changed lines shall be written as:</p>
|
|
|
|
<pre>
|
|
<tt>"!<img src="../images/delta.gif" border="0">%s", <</tt><i>changed_line</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>Next, the range of lines in <i>file2</i> shall be written in the following format:</p>
|
|
|
|
<pre>
|
|
<tt>"--- %d,%d ----\n", <</tt><i>beginning line number</i><tt>>, <</tt><i>ending line number</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>Then, lines of context and changed lines shall be written as described in the previous formats. Lines added from <i>file2</i>
|
|
shall be written in the following format:</p>
|
|
|
|
<pre>
|
|
<tt>"+<img src="../images/delta.gif" border="0">%s", <</tt><i>added_line</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_11"></a>STDERR</h4>
|
|
|
|
<blockquote>
|
|
<p>The standard error shall be used only for diagnostic messages.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_12"></a>OUTPUT FILES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_13"></a>EXTENDED DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_14"></a>EXIT STATUS</h4>
|
|
|
|
<blockquote>
|
|
<p>The following exit values shall be returned:</p>
|
|
|
|
<dl compact>
|
|
<dt> 0</dt>
|
|
|
|
<dd>No differences were found.</dd>
|
|
|
|
<dt> 1</dt>
|
|
|
|
<dd>Differences were found.</dd>
|
|
|
|
<dt>>1</dt>
|
|
|
|
<dd>An error occurred.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_15"></a>CONSEQUENCES OF ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>Default.</p>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_04_37_16"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>If lines at the end of a file are changed and other lines are added, <i>diff</i> output may show this as a delete and add, as a
|
|
change, or as a change and add; <i>diff</i> is not expected to know which happened and users should not care about the difference
|
|
in output as long as it clearly shows the differences between the files.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_17"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>If <b>dir1</b> is a directory containing a directory named <b>x</b>, <b>dir2</b> is a directory containing a directory named
|
|
<b>x</b>, <b>dir1/x</b> and <b>dir2/x</b> both contain files named <b>date.out</b>, and <b>dir2/x</b> contains a file named
|
|
<b>y</b>, the command:</p>
|
|
|
|
<pre>
|
|
<tt>diff -r dir1 dir2
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>could produce output similar to:</p>
|
|
|
|
<pre>
|
|
<tt>Common subdirectories: dir1/x and dir2/x
|
|
Only in dir2/x: y
|
|
diff -r dir1/x/date.out dir2/x/date.out
|
|
1c1
|
|
< Mon Jul 2 13:12:16 PDT 1990
|
|
---
|
|
> Tue Jun 19 21:41:39 PDT 1990
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_18"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>The <b>-h</b> option was omitted because it was insufficiently specified and does not add to applications portability.</p>
|
|
|
|
<p>Historical implementations employ algorithms that do not always produce a minimum list of differences; the current language
|
|
about making every effort is the best this volume of IEEE Std 1003.1-2001 can do, as there is no metric that could be
|
|
employed to judge the quality of implementations against any and all file contents. The statement "This list should be minimal''
|
|
clearly implies that implementations are not expected to provide the following output when comparing two 100-line files that differ
|
|
in only one character on a single line:</p>
|
|
|
|
<pre>
|
|
<tt>1,100c1,100
|
|
all 100 lines from file1 preceded with "< "
|
|
---
|
|
all 100 lines from file2 preceded with "> "
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>The "Only in" messages required when the <b>-r</b> option is specified are not used by most historical implementations if the
|
|
<b>-e</b> option is also specified. It is required here because it provides useful information that must be provided to update a
|
|
target directory hierarchy to match a source hierarchy. The "Common subdirectories" messages are written by System V and 4.3 BSD
|
|
when the <b>-r</b> option is specified. They are allowed here but are not required because they are reporting on something that is
|
|
the same, not reporting a difference, and are not needed to update a target hierarchy.</p>
|
|
|
|
<p>The <b>-c</b> option, which writes output in a format using lines of context, has been included. The format is useful for a
|
|
variety of reasons, among them being much improved readability and the ability to understand difference changes when the target
|
|
file has line numbers that differ from another similar, but slightly different, copy. The <a href=
|
|
"../utilities/patch.html"><i>patch</i></a> utility is most valuable when working with difference listings using the context format.
|
|
The BSD version of <b>-c</b> takes an optional argument specifying the amount of context. Rather than overloading <b>-c</b> and
|
|
breaking the Utility Syntax Guidelines for <i>diff</i>, the standard developers decided to add a separate option for specifying a
|
|
context diff with a specified amount of context ( <b>-C</b>). Also, the format for context <i>diff</i>s was extended slightly in
|
|
4.3 BSD to allow multiple changes that are within context lines from each other to be merged together. The output format contains
|
|
an additional four asterisks after the range of affected lines in the first filename. This was to provide a flag for old programs
|
|
(like old versions of <a href="../utilities/patch.html"><i>patch</i></a>) that only understand the old context format. The version
|
|
of context described here does not require that multiple changes within context lines be merged, but it does not prohibit it
|
|
either. The extension is upwards-compatible, so any vendors that wish to retain the old version of <i>diff</i> can do so by adding
|
|
the extra four asterisks (that is, utilities that currently use <i>diff</i> and understand the new merged format will also
|
|
understand the old unmerged format, but not <i>vice versa</i>).</p>
|
|
|
|
<p>The substitute command was added as an additional format for the <b>-e</b> option. This was added to provide implementations
|
|
with a way to fix the classic "dot alone on a line" bug present in many versions of <i>diff</i>. Since many implementations have
|
|
fixed this bug, the standard developers decided not to standardize broken behavior, but rather to provide the necessary tool for
|
|
fixing the bug. One way to fix this bug is to output two periods whenever a lone period is needed, then terminate the append
|
|
command with a period, and then use the substitute command to convert the two periods into one period.</p>
|
|
|
|
<p>The BSD-derived <b>-r</b> option was added to provide a mechanism for using <i>diff</i> to compare two file system trees. This
|
|
behavior is useful, is standard practice on all BSD-derived systems, and is not easily reproducible with the <a href=
|
|
"../utilities/find.html"><i>find</i></a> utility.</p>
|
|
|
|
<p>The requirement that <i>diff</i> not compare files in some circumstances, even though they have the same name, is based on the
|
|
actual output of historical implementations. The message specified here is already in use when a directory is being compared to a
|
|
non-directory. It is extended here to preclude the problems arising from running into FIFOs and other files that would cause
|
|
<i>diff</i> to hang waiting for input with no indication to the user that <i>diff</i> was hung. In most common usage, <i>diff</i>
|
|
<b>-r</b> should indicate differences in the file hierarchies, not the difference of contents of devices pointed to by the
|
|
hierarchies.</p>
|
|
|
|
<p>Many early implementations of <i>diff</i> require seekable files. Since the System Interfaces volume of
|
|
IEEE Std 1003.1-2001 supports named pipes, the standard developers decided that such a restriction was unreasonable. Note
|
|
also that the allowed filename <b>-</b> almost always refers to a pipe.</p>
|
|
|
|
<p>No directory search order is specified for <i>diff</i>. The historical ordering is, in fact, not optimal, in that it prints out
|
|
all of the differences at the current level, including the statements about all common subdirectories before recursing into those
|
|
subdirectories.</p>
|
|
|
|
<p>The message:</p>
|
|
|
|
<pre>
|
|
<tt>"diff %s %s %s\n", <</tt><i>diff_options</i><tt>>, <</tt><i>filename1</i><tt>>, <</tt><i>filename2</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>does not vary by locale because it is the representation of a command, not an English sentence.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_19"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_20"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="cmp.html"><i>cmp</i></a> , <a href="comm.html"><i>comm</i></a> , <a href="ed.html"><i>ed</i></a> , <a href=
|
|
"find.html"><i>find</i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_21"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 2.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_22"></a>Issue 5</h4>
|
|
|
|
<blockquote>
|
|
<p>The FUTURE DIRECTIONS section is added.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_04_37_23"></a>Issue 6</h4>
|
|
|
|
<blockquote>
|
|
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>The <b>-f</b> option is added.</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<p>The output format for <b>-c</b> or <b>-C</b> format is changed to align with changes to the IEEE P1003.2b draft standard
|
|
resulting from IEEE PASC Interpretation 1003.2 #71.</p>
|
|
|
|
<p>The normative text is reworded to avoid use of the term "must" for application requirements.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|