Un outil pour savoir si une commande est posix - retour accueil
git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |
cmp.html (14634B)
1 <!-- Copyright 2001-2024 IEEE and The Open Group, All Rights Reserved --> 2 <!DOCTYPE HTML> 3 <html lang="en"> 4 <head> 5 <meta name="generator" content="HTML Tidy for HTML5 for Linux version 5.8.0"> 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 7 <link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group rhtm tool v1.2.4 --> 8 <!-- Copyright (c) 2001-2024 The Open Group, All Rights Reserved --> 9 <title>cmp</title> 10 </head> 11 <body bgcolor="white"> 12 <div class="NAVHEADER"> 13 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0"> 14 <tr class="nav"> 15 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/cksum.html" accesskey="P"><<< 16 Previous</a></td> 17 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td> 18 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/comm.html" accesskey="N">Next >>></a></td> 19 </tr> 20 </table> 21 <hr align="left" width="100%"></div> 22 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> 23 <center><font size="2">The Open Group Base Specifications Issue 8<br> 24 IEEE Std 1003.1-2024<br> 25 Copyright © 2001-2024 The IEEE and The Open Group</font></center> 26 <hr size="2" noshade> 27 <a name="top" id="top"></a> <a name="cmp" id="cmp"></a> <a name="tag_20_20" id="tag_20_20"></a><!-- cmp --> 28 <h4 class="mansect"><a name="tag_20_20_01" id="tag_20_20_01"></a>NAME</h4> 29 <blockquote>cmp — compare two files</blockquote> 30 <h4 class="mansect"><a name="tag_20_20_02" id="tag_20_20_02"></a>SYNOPSIS</h4> 31 <blockquote class="synopsis"> 32 <p><code><tt>cmp</tt> <b>[</b><tt>-l|-s</tt><b>]</b> <i>file1 file2</i></code></p> 33 </blockquote> 34 <h4 class="mansect"><a name="tag_20_20_03" id="tag_20_20_03"></a>DESCRIPTION</h4> 35 <blockquote> 36 <p>The <i>cmp</i> utility shall compare two files. The <i>cmp</i> utility shall write no output if the files are the same. Under 37 default options, if they differ, it shall write to standard output the byte and line number at which the first difference occurred. 38 Bytes and lines shall be numbered beginning with 1.</p> 39 </blockquote> 40 <h4 class="mansect"><a name="tag_20_20_04" id="tag_20_20_04"></a>OPTIONS</h4> 41 <blockquote> 42 <p>The <i>cmp</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax 43 Guidelines</i></a> .</p> 44 <p>The following options shall be supported:</p> 45 <dl compact> 46 <dd></dd> 47 <dt><b>-l</b></dt> 48 <dd>(Lowercase ell.) Write the byte number (decimal) and the differing bytes (octal) for each difference.</dd> 49 <dt><b>-s</b></dt> 50 <dd>Write nothing to standard output or standard error when files differ; indicate differing files through exit status only. It is 51 unspecified whether a diagnostic message is written to standard error when an error is encountered; if a message is not written, 52 the error is indicated through exit status only.</dd> 53 </dl> 54 </blockquote> 55 <h4 class="mansect"><a name="tag_20_20_05" id="tag_20_20_05"></a>OPERANDS</h4> 56 <blockquote> 57 <p>The following operands shall be supported:</p> 58 <dl compact> 59 <dd></dd> 60 <dt><i>file1</i></dt> 61 <dd>A pathname of the first file to be compared. If <i>file1</i> is <tt>'-'</tt>, the standard input shall be used.</dd> 62 <dt><i>file2</i></dt> 63 <dd>A pathname of the second file to be compared. If <i>file2</i> is <tt>'-'</tt>, the standard input shall be used.</dd> 64 </dl> 65 <p>If both <i>file1</i> and <i>file2</i> refer to standard input or refer to the same FIFO special, block special, or character 66 special file, the results are undefined.</p> 67 </blockquote> 68 <h4 class="mansect"><a name="tag_20_20_06" id="tag_20_20_06"></a>STDIN</h4> 69 <blockquote> 70 <p>The standard input shall be used only if the <i>file1</i> or <i>file2</i> operand refers to standard input. See the INPUT FILES 71 section.</p> 72 </blockquote> 73 <h4 class="mansect"><a name="tag_20_20_07" id="tag_20_20_07"></a>INPUT FILES</h4> 74 <blockquote> 75 <p>The input files can be any file type.</p> 76 </blockquote> 77 <h4 class="mansect"><a name="tag_20_20_08" id="tag_20_20_08"></a>ENVIRONMENT VARIABLES</h4> 78 <blockquote> 79 <p>The following environment variables shall affect the execution of <i>cmp</i>:</p> 80 <dl compact> 81 <dd></dd> 82 <dt><i>LANG</i></dt> 83 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href= 84 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization 85 variables used to determine the values of locale categories.)</dd> 86 <dt><i>LC_ALL</i></dt> 87 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd> 88 <dt><i>LC_CTYPE</i></dt> 89 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as 90 opposed to multi-byte characters in arguments).</dd> 91 <dt><i>LC_MESSAGES</i></dt> 92 <dd><br> 93 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and 94 informative messages written to standard output.</dd> 95 <dt><i>NLSPATH</i></dt> 96 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> 97 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border= 98 "0"></dd> 99 </dl> 100 </blockquote> 101 <h4 class="mansect"><a name="tag_20_20_09" id="tag_20_20_09"></a>ASYNCHRONOUS EVENTS</h4> 102 <blockquote> 103 <p>Default.</p> 104 </blockquote> 105 <h4 class="mansect"><a name="tag_20_20_10" id="tag_20_20_10"></a>STDOUT</h4> 106 <blockquote> 107 <p>In the POSIX locale, results of the comparison shall be written to standard output. When no options are used, the format shall 108 be:</p> 109 <pre> 110 <tt>"%s %s differ: char %d, line %d\n", </tt><i>file1</i><tt>, </tt><i>file2</i><tt>, 111 <</tt><i>byte number</i><tt>>, <</tt><i>line number</i><tt>> 112 </tt></pre> 113 <p>When the <b>-l</b> option is used, the format shall be:</p> 114 <pre> 115 <tt>"%d %o %o\n", <</tt><i>byte number</i><tt>>, <</tt><i>differing byte</i><tt>>, 116 <</tt><i>differing byte</i><tt>> 117 </tt></pre> 118 <p>for each byte that differs. The first <<i>differing byte</i>> number is from <i>file1</i> while the second is from 119 <i>file2</i>. In both cases, <<i>byte number</i>> shall be relative to the beginning of the file, beginning with 1.</p> 120 <p>No output shall be written to standard output when the <b>-s</b> option is used.</p> 121 </blockquote> 122 <h4 class="mansect"><a name="tag_20_20_11" id="tag_20_20_11"></a>STDERR</h4> 123 <blockquote> 124 <p>The standard error shall be used only for diagnostic messages. If the <b>-l</b> option is used and <i>file1</i> and <i>file2</i> 125 differ in length, or if the <b>-s</b> option is not used and <i>file1</i> and <i>file2</i> are identical for the entire length of 126 the shorter file, in the POSIX locale the following diagnostic message shall be written:</p> 127 <pre> 128 <tt>"cmp: EOF on %s%s\n", <</tt><i>name of shorter file</i><tt>>, <</tt><i>additional info</i><tt>> 129 </tt></pre> 130 <p>The <<i>additional info</i>> field shall either be null or a string that starts with a <blank> and contains no 131 <newline> characters. Some implementations report on the number of lines in this case.</p> 132 <p>If the <b>-s</b> option is used and an error occurs, it is unspecified whether a diagnostic message is written to standard 133 error.</p> 134 </blockquote> 135 <h4 class="mansect"><a name="tag_20_20_12" id="tag_20_20_12"></a>OUTPUT FILES</h4> 136 <blockquote> 137 <p>None.</p> 138 </blockquote> 139 <h4 class="mansect"><a name="tag_20_20_13" id="tag_20_20_13"></a>EXTENDED DESCRIPTION</h4> 140 <blockquote> 141 <p>None.</p> 142 </blockquote> 143 <h4 class="mansect"><a name="tag_20_20_14" id="tag_20_20_14"></a>EXIT STATUS</h4> 144 <blockquote> 145 <p>The following exit values shall be returned:</p> 146 <dl compact> 147 <dd></dd> 148 <dt> 0</dt> 149 <dd>The files are identical.</dd> 150 <dt> 1</dt> 151 <dd>The files are different; this includes the case where one file is identical to the first part of the other.</dd> 152 <dt>>1</dt> 153 <dd>An error occurred.</dd> 154 </dl> 155 </blockquote> 156 <h4 class="mansect"><a name="tag_20_20_15" id="tag_20_20_15"></a>CONSEQUENCES OF ERRORS</h4> 157 <blockquote> 158 <p>Default.</p> 159 </blockquote> 160 <hr> 161 <div class="box"><em>The following sections are informative.</em></div> 162 <h4 class="mansect"><a name="tag_20_20_16" id="tag_20_20_16"></a>APPLICATION USAGE</h4> 163 <blockquote> 164 <p>Although input files to <i>cmp</i> can be any type, the results might not be what would be expected on character special device 165 files or on file types not described by the System Interfaces volume of POSIX.1-2024. Since this volume of POSIX.1-2024 does not 166 specify the block size used when doing input, comparisons of character special files need not compare all of the data in those 167 files.</p> 168 <p>For files which are not text files, line numbers simply reflect the presence of a <newline>, without any implication that 169 the file is organized into lines.</p> 170 <p>Since the behavior of <b>-s</b> differs between implementations as to whether error messages are written, the only way to ensure 171 consistent behavior of <i>cmp</i> when <b>-s</b> is used is to redirect standard error to <b>/dev/null</b>.</p> 172 <p>If error messages are wanted, instead of using <b>-s</b> standard output should be redirected to <b>/dev/null</b>, and anything 173 written to standard error should be discarded if the exit status is 1. For example:</p> 174 <pre> 175 <tt>silent_cmp() { 176 # compare files with no output except error messages 177 message=$(cmp "$@" 2>&1 >/dev/null) 178 status=$? 179 case $status in 180 (0|1) ;; 181 (*) printf '%s\n' "$message" ;; 182 esac 183 return $status 184 } 185 </tt></pre></blockquote> 186 <h4 class="mansect"><a name="tag_20_20_17" id="tag_20_20_17"></a>EXAMPLES</h4> 187 <blockquote> 188 <p>None.</p> 189 </blockquote> 190 <h4 class="mansect"><a name="tag_20_20_18" id="tag_20_20_18"></a>RATIONALE</h4> 191 <blockquote> 192 <p>The global language in <a href="../utilities/V3_chap01.html#tag_18_04"><i>1.4 Utility Description Defaults</i></a> indicates 193 that using two mutually-exclusive options together produces unspecified results. Some System V implementations consider the option 194 usage:</p> 195 <pre> 196 <tt>cmp -l -s ... 197 </tt></pre> 198 <p>to be an error. They also treat:</p> 199 <pre> 200 <tt>cmp -s -l ... 201 </tt></pre> 202 <p>as if no options were specified. Both of these behaviors are considered bugs, but are allowed.</p> 203 <p>The word <b>char</b> in the standard output format comes from historical usage, even though it is actually a byte number. When 204 <i>cmp</i> is supported in other locales, implementations are encouraged to use the word <i>byte</i> or its equivalent in another 205 language. Users should not interpret this difference to indicate that the functionality of the utility changed between locales.</p> 206 <p>Some implementations report on the number of lines in the identical-but-shorter file case. This is allowed by the inclusion of 207 the <<i>additional info</i>> fields in the output format. The restriction on having a leading <blank> and no 208 <newline> characters is to make parsing for the filename easier. It is recognized that some filenames containing white-space 209 characters make parsing difficult anyway, but the restriction does aid programs used on systems where the names are predominantly 210 well behaved.</p> 211 </blockquote> 212 <h4 class="mansect"><a name="tag_20_20_19" id="tag_20_20_19"></a>FUTURE DIRECTIONS</h4> 213 <blockquote> 214 <p>If this utility is directed to display a pathname that contains any bytes that have the encoded value of a <newline> 215 character when <newline> is a terminator or separator in the output format being used, implementations are encouraged to 216 treat this as an error. A future version of this standard may require implementations to treat this as an error.</p> 217 <p>Future versions of this standard may require that diagnostic messages are written to standard error when the <b>-s</b> option is 218 specified.</p> 219 </blockquote> 220 <h4 class="mansect"><a name="tag_20_20_20" id="tag_20_20_20"></a>SEE ALSO</h4> 221 <blockquote> 222 <p><a href="../utilities/comm.html#"><i>comm</i></a> , <a href="../utilities/diff.html#"><i>diff</i></a></p> 223 <p>XBD <a href="../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href= 224 "../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax Guidelines</i></a></p> 225 </blockquote> 226 <h4 class="mansect"><a name="tag_20_20_21" id="tag_20_20_21"></a>CHANGE HISTORY</h4> 227 <blockquote> 228 <p>First released in Issue 2.</p> 229 </blockquote> 230 <h4 class="mansect"><a name="tag_20_20_22" id="tag_20_20_22"></a>Issue 7</h4> 231 <blockquote> 232 <p>SD5-XCU-ERN-96 is applied, updating the STDERR section.</p> 233 <p>SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.</p> 234 <p>POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0075 [478] is applied.</p> 235 </blockquote> 236 <h4 class="mansect"><a name="tag_20_20_23" id="tag_20_20_23"></a>Issue 8</h4> 237 <blockquote> 238 <p>Austin Group Defect 251 is applied, encouraging implementations to report an error if a utility is directed to display a 239 pathname that contains any bytes that have the encoded value of a <newline> character when <newline> is a terminator or 240 separator in the output format being used.</p> 241 <p>Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p> 242 </blockquote> 243 <div class="box"><em>End of informative text.</em></div> 244 <hr> 245 <p> </p> 246 <a href="#top"><span class="topOfPage">return to top of page</span></a><br> 247 <hr size="2" noshade> 248 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br> 249 POSIX™ is a Trademark of The IEEE.<br> 250 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br> 251 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href= 252 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a> 253 ]</font></center> 254 <hr size="2" noshade> 255 <div class="NAVHEADER"> 256 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0"> 257 <tr class="nav"> 258 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/cksum.html" accesskey="P"><<< 259 Previous</a></td> 260 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td> 261 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/comm.html" accesskey="N">Next >>></a></td> 262 </tr> 263 </table> 264 <hr align="left" width="100%"></div> 265 </body> 266 </html>