Un outil pour savoir si une commande est posix - retour accueil
git clone git://bebou.netlib.re/isposix
Log | Files | Refs | README |
sort.html (31046B)
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>sort</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/sleep.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/split.html" accesskey="N">Next 19 >>></a></td> 20 </tr> 21 </table> 22 <hr align="left" width="100%"></div> 23 <script language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> 24 <center><font size="2">The Open Group Base Specifications Issue 8<br> 25 IEEE Std 1003.1-2024<br> 26 Copyright © 2001-2024 The IEEE and The Open Group</font></center> 27 <hr size="2" noshade> 28 <a name="top" id="top"></a> <a name="sort" id="sort"></a> <a name="tag_20_112" id="tag_20_112"></a><!-- sort --> 29 <h4 class="mansect"><a name="tag_20_112_01" id="tag_20_112_01"></a>NAME</h4> 30 <blockquote>sort — sort, merge, or sequence check text files</blockquote> 31 <h4 class="mansect"><a name="tag_20_112_02" id="tag_20_112_02"></a>SYNOPSIS</h4> 32 <blockquote class="synopsis"> 33 <p><code><tt>sort</tt> <b>[</b><tt>-m</tt><b>] [</b><tt>-o</tt> <i>output</i><b>] [</b><tt>-bdfinru</tt><b>] [</b><tt>-t</tt> 34 <i>char</i><b>] [</b><tt>-k</tt> <i>keydef</i><b>]</b><tt>...</tt> <b>[</b><i>file</i><tt>...</tt><b>]</b> <tt><br> 35 <br> 36 sort</tt> <b>[</b><tt>-c|-C</tt><b>] [</b><tt>-bdfinru</tt><b>] [</b><tt>-t</tt> <i>char</i><b>] [</b><tt>-k</tt> <i>keydef</i><b>] 37 [</b><i>file</i><b>]</b> <tt><br></tt></code></p> 38 </blockquote> 39 <h4 class="mansect"><a name="tag_20_112_03" id="tag_20_112_03"></a>DESCRIPTION</h4> 40 <blockquote> 41 <p>The <i>sort</i> utility shall perform one of the following functions:</p> 42 <ol> 43 <li> 44 <p>Sort lines of all the named files together and write the result to the specified output.</p> 45 </li> 46 <li> 47 <p>Merge lines of all the named (presorted) files together and write the result to the specified output.</p> 48 </li> 49 <li> 50 <p>Check that a single input file is correctly presorted.</p> 51 </li> 52 </ol> 53 <p>Comparisons shall be based on one or more sort keys extracted from each line of input (or, if no sort keys are specified, the 54 entire line up to, but not including, the terminating <newline>), and shall be performed using the collating sequence of the 55 current locale. If this collating sequence does not have a total ordering of all characters (see XBD <a href= 56 "../basedefs/V1_chap07.html#tag_07_03_02"><i>7.3.2 LC_COLLATE</i></a> ), any lines of input that collate equally shall be further 57 compared byte-by-byte using the collating sequence for the POSIX locale.</p> 58 </blockquote> 59 <h4 class="mansect"><a name="tag_20_112_04" id="tag_20_112_04"></a>OPTIONS</h4> 60 <blockquote> 61 <p>The <i>sort</i> utility shall conform to XBD <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 Utility Syntax 62 Guidelines</i></a> , except for Guideline 9, and the <b>-k</b> <i>keydef</i> option should follow the <b>-b</b>, <b>-d</b>, 63 <b>-f</b>, <b>-i</b>, <b>-n</b>, and <b>-r</b> options. In addition, <tt>'+'</tt> may be recognized as an option delimiter as well 64 as <tt>'-'</tt>.</p> 65 <p>The following options shall be supported:</p> 66 <dl compact> 67 <dd></dd> 68 <dt><b>-c</b></dt> 69 <dd>Check that the single input file is ordered as specified by the arguments and the collating sequence of the current locale. 70 Output shall not be sent to standard output. The exit code shall indicate whether or not disorder was detected or an error 71 occurred. If disorder (or, with <b>-u</b>, a duplicate key) is detected, a warning message shall be sent to standard error 72 indicating where the disorder or duplicate key was found.</dd> 73 <dt><b>-C</b></dt> 74 <dd>Same as <b>-c</b>, except that a warning message shall not be sent to standard error if disorder or, with <b>-u</b>, a 75 duplicate key is detected.</dd> 76 <dt><b>-m</b></dt> 77 <dd>Merge only; the input file shall be assumed to be already sorted.</dd> 78 <dt><b>-o </b><i>output</i></dt> 79 <dd>Specify the name of an output file to be used instead of the standard output. This file can be the same as one of the input 80 <i>file</i>s.</dd> 81 <dt><b>-u</b></dt> 82 <dd>Unique: suppress all but one in each set of lines having equal keys. If used with the <b>-c</b> option, check that there are no 83 lines with duplicate keys, in addition to checking that the input file is sorted.</dd> 84 </dl> 85 <p>The following options shall override the default ordering rules. When ordering options appear independent of any key field 86 specifications, the requested field ordering rules shall be applied globally to all sort keys. When attached to a specific key (see 87 <b>-k</b>), the specified ordering options shall override all global ordering options for that key.</p> 88 <dl compact> 89 <dd></dd> 90 <dt><b>-d</b></dt> 91 <dd>Specify that only <blank> characters and alphanumeric characters, according to the current setting of <i>LC_CTYPE ,</i> 92 shall be significant in comparisons. The behavior is undefined for a sort key to which <b>-i</b> or <b>-n</b> also applies.</dd> 93 <dt><b>-f</b></dt> 94 <dd>Consider all lowercase characters that have uppercase equivalents, according to the current setting of <i>LC_CTYPE ,</i> to be 95 the uppercase equivalent for the purposes of comparison.</dd> 96 <dt><b>-i</b></dt> 97 <dd>Ignore all characters that are non-printable, according to the current setting of <i>LC_CTYPE .</i> The behavior is undefined 98 for a sort key for which <b>-n</b> also applies.</dd> 99 <dt><b>-n</b></dt> 100 <dd>Restrict the sort key to an initial numeric string, consisting of optional <blank> characters, optional 101 <hyphen-minus> character, and zero or more digits with an optional radix character and thousands separators (as defined in 102 the current locale), which shall be sorted by arithmetic value. An empty digit string shall be treated as zero. Leading zeros and 103 signs on zeros shall not affect ordering.</dd> 104 <dt><b>-r</b></dt> 105 <dd>Reverse the sense of comparisons.</dd> 106 </dl> 107 <p>The treatment of field separators can be altered using the options:</p> 108 <dl compact> 109 <dd></dd> 110 <dt><b>-b</b></dt> 111 <dd>Ignore leading <blank> characters when determining the starting and ending positions of a restricted sort key. If the 112 <b>-b</b> option is specified before the first <b>-k</b> option, it shall be applied to all <b>-k</b> options. Otherwise, the 113 <b>-b</b> option can be attached independently to each <b>-k</b> <i>field_start</i> or <i>field_end</i> option-argument (see 114 below).</dd> 115 <dt><b>-t </b><i>char</i></dt> 116 <dd>Use <i>char</i> as the field separator character; <i>char</i> shall not be considered to be part of a field (although it can be 117 included in a sort key). Each occurrence of <i>char</i> shall be significant (for example, <<i>char</i>><<i>char</i>> 118 delimits an empty field). If <b>-t</b> is not specified, <blank> characters shall be used as default field separators; each 119 maximal non-empty sequence of <blank> characters that follows a non-<blank> shall be a field separator.</dd> 120 </dl> 121 <p>Sort keys can be specified using the options:</p> 122 <dl compact> 123 <dd></dd> 124 <dt><b>-k </b><i>keydef</i></dt> 125 <dd>The <i>keydef</i> argument is a restricted sort key field definition. The format of this definition is: 126 <pre> 127 <i>field_start</i><b>[</b><i>type</i><b>][</b><tt>,</tt><i>field_end</i><b>[</b><i>type</i><b>]]</b><tt> 128 </tt></pre> 129 <p>where <i>field_start</i> and <i>field_end</i> define a key field restricted to a portion of the line (see the EXTENDED 130 DESCRIPTION section), and <i>type</i> is one or more modifiers from the list of characters <tt>'b'</tt>, <tt>'d'</tt>, 131 <tt>'f'</tt>, <tt>'i'</tt>, <tt>'n'</tt>, <tt>'r'</tt>. The <tt>'b'</tt> modifier shall behave like the <b>-b</b> option, but shall 132 apply only to the <i>field_start</i> or <i>field_end</i> to which it is attached. The other modifiers shall behave like the 133 corresponding options, but shall apply only to the key field to which they are attached; they shall have this effect if specified 134 with <i>field_start</i>, <i>field_end</i>, or both. If any modifier is attached to a <i>field_start</i> or to a <i>field_end</i>, 135 no option shall apply to either. Implementations shall support at least nine occurrences of the <b>-k</b> option, which shall be 136 significant in command line order. If no <b>-k</b> option is specified, a default sort key of the entire line shall be used.</p> 137 <p>When there are multiple key fields, later keys shall be compared only after all earlier keys compare equal. Except when the 138 <b>-u</b> option is specified, lines that otherwise compare equal shall be ordered as if none of the options <b>-d</b>, <b>-f</b>, 139 <b>-i</b>, <b>-n</b>, or <b>-k</b> were present (but with <b>-r</b> still in effect, if it was specified) and with all bytes in the 140 lines significant to the comparison. The order in which lines that still compare equal are written is unspecified.</p> 141 </dd> 142 </dl> 143 </blockquote> 144 <h4 class="mansect"><a name="tag_20_112_05" id="tag_20_112_05"></a>OPERANDS</h4> 145 <blockquote> 146 <p>The following operand shall be supported:</p> 147 <dl compact> 148 <dd></dd> 149 <dt><i>file</i></dt> 150 <dd>A pathname of a file to be sorted, merged, or checked. If no <i>file</i> operands are specified, or if a <i>file</i> operand is 151 <tt>'-'</tt>, the standard input shall be used. If <i>sort</i> encounters an error when opening or reading a <i>file</i> operand, 152 it may exit without writing any output to standard output or processing later operands.</dd> 153 </dl> 154 </blockquote> 155 <h4 class="mansect"><a name="tag_20_112_06" id="tag_20_112_06"></a>STDIN</h4> 156 <blockquote> 157 <p>The standard input shall be used only if no <i>file</i> operands are specified, or if a <i>file</i> operand is <tt>'-'</tt>. See 158 the INPUT FILES section.</p> 159 </blockquote> 160 <h4 class="mansect"><a name="tag_20_112_07" id="tag_20_112_07"></a>INPUT FILES</h4> 161 <blockquote> 162 <p>The input files shall be text files, except that the <i>sort</i> utility shall add a <newline> to the end of a file ending 163 with an incomplete last line.</p> 164 </blockquote> 165 <h4 class="mansect"><a name="tag_20_112_08" id="tag_20_112_08"></a>ENVIRONMENT VARIABLES</h4> 166 <blockquote> 167 <p>The following environment variables shall affect the execution of <i>sort</i>:</p> 168 <dl compact> 169 <dd></dd> 170 <dt><i>LANG</i></dt> 171 <dd>Provide a default value for the internationalization variables that are unset or null. (See XBD <a href= 172 "../basedefs/V1_chap08.html#tag_08_02"><i>8.2 Internationalization Variables</i></a> for the precedence of internationalization 173 variables used to determine the values of locale categories.)</dd> 174 <dt><i>LC_ALL</i></dt> 175 <dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd> 176 <dt><i>LC_COLLATE</i></dt> 177 <dd><br> 178 Determine the locale for ordering rules.</dd> 179 <dt><i>LC_CTYPE</i></dt> 180 <dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as 181 opposed to multi-byte characters in arguments and input files) and the behavior of character classification for the <b>-b</b>, 182 <b>-d</b>, <b>-f</b>, <b>-i</b>, and <b>-n</b> options.</dd> 183 <dt><i>LC_MESSAGES</i></dt> 184 <dd><br> 185 Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.</dd> 186 <dt><i>LC_NUMERIC</i></dt> 187 <dd><br> 188 Determine the locale for the definition of the radix character and thousands separator for the <b>-n</b> option.</dd> 189 <dt><i>NLSPATH</i></dt> 190 <dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> 191 Determine the location of messages objects and message catalogs. <img src="../images/opt-end.gif" alt="[Option End]" border= 192 "0"></dd> 193 <dt><i>TMPDIR</i></dt> 194 <dd>Provide a pathname that shall override the default directory for temporary files, if any.</dd> 195 </dl> 196 </blockquote> 197 <h4 class="mansect"><a name="tag_20_112_09" id="tag_20_112_09"></a>ASYNCHRONOUS EVENTS</h4> 198 <blockquote> 199 <p>Default.</p> 200 </blockquote> 201 <h4 class="mansect"><a name="tag_20_112_10" id="tag_20_112_10"></a>STDOUT</h4> 202 <blockquote> 203 <p>Unless the <b>-o</b> or <b>-c</b> options are in effect, the standard output shall contain the sorted input.</p> 204 </blockquote> 205 <h4 class="mansect"><a name="tag_20_112_11" id="tag_20_112_11"></a>STDERR</h4> 206 <blockquote> 207 <p>The standard error shall be used for diagnostic messages. When <b>-c</b> is specified, if disorder is detected (or if <b>-u</b> 208 is also specified and a duplicate key is detected), a message shall be written to the standard error which identifies the input 209 line at which disorder (or a duplicate key) was detected. A warning message about correcting an incomplete last line of an input 210 file may be generated, but need not affect the final exit status.</p> 211 </blockquote> 212 <h4 class="mansect"><a name="tag_20_112_12" id="tag_20_112_12"></a>OUTPUT FILES</h4> 213 <blockquote> 214 <p>If the <b>-o</b> option is in effect, the sorted input shall be written to the file <i>output</i>.</p> 215 </blockquote> 216 <h4 class="mansect"><a name="tag_20_112_13" id="tag_20_112_13"></a>EXTENDED DESCRIPTION</h4> 217 <blockquote> 218 <p>The notation:</p> 219 <pre> 220 <tt>-k </tt><i>field_start</i><b>[</b><i>type</i><b>][</b><tt>,</tt><i>field_end</i><b>[</b><i>type</i><b>]]</b><tt> 221 </tt></pre> 222 <p>shall define a key field that begins at <i>field_start</i> and ends at <i>field_end</i> inclusive, unless <i>field_start</i> 223 falls beyond the end of the line or after <i>field_end</i>, in which case the key field is empty. A missing <i>field_end</i> shall 224 mean the last character of the line.</p> 225 <p>A field comprises a maximal sequence of non-separating characters and, in the absence of option <b>-t</b>, any preceding field 226 separator.</p> 227 <p>The <i>field_start</i> portion of the <i>keydef</i> option-argument shall have the form:</p> 228 <pre> 229 <i>field_number</i><b>[</b><tt>.</tt><i>first_character</i><b>]</b><tt> 230 </tt></pre> 231 <p>Fields and characters within fields shall be numbered starting with 1. The <i>field_number</i> and <i>first_character</i> 232 pieces, interpreted as positive decimal integers, shall specify the first character to be used as part of a sort key. If 233 <i>.first_character</i> is omitted, it shall refer to the first character of the field.</p> 234 <p>The <i>field_end</i> portion of the <i>keydef</i> option-argument shall have the form:</p> 235 <pre> 236 <i>field_number</i><b>[</b><tt>.</tt><i>last_character</i><b>]</b><tt> 237 </tt></pre> 238 <p>The <i>field_number</i> shall be as described above for <i>field_start.</i> The <i>last_character</i> piece, interpreted as a 239 non-negative decimal integer, shall specify the last character to be used as part of the sort key. If <i>last_character</i> 240 evaluates to zero or <i>.last_character</i> is omitted, it shall refer to the last character of the field specified by 241 <i>field_number</i>.</p> 242 <p>If the <b>-b</b> option or <b>b</b> type modifier is in effect, characters within a field shall be counted from the first 243 non-<blank> in the field. (This shall apply separately to <i>first_character</i> and <i>last_character</i>.)</p> 244 </blockquote> 245 <h4 class="mansect"><a name="tag_20_112_14" id="tag_20_112_14"></a>EXIT STATUS</h4> 246 <blockquote> 247 <p>The following exit values shall be returned:</p> 248 <dl compact> 249 <dd></dd> 250 <dt> 0</dt> 251 <dd>All input files were output successfully, or <b>-c</b> was specified and the input file was correctly sorted.</dd> 252 <dt> 1</dt> 253 <dd>Under the <b>-c</b> option, the file was not ordered as specified, or if the <b>-c</b> and <b>-u</b> options were both 254 specified, two input lines were found with equal keys.</dd> 255 <dt>>1</dt> 256 <dd>An error occurred.</dd> 257 </dl> 258 </blockquote> 259 <h4 class="mansect"><a name="tag_20_112_15" id="tag_20_112_15"></a>CONSEQUENCES OF ERRORS</h4> 260 <blockquote> 261 <p>The default requirements shall apply, except that if <i>sort</i> encounters an error when opening or reading a <i>file</i> 262 operand, it may exit without writing any output to standard output or processing later operands.</p> 263 </blockquote> 264 <hr> 265 <div class="box"><em>The following sections are informative.</em></div> 266 <h4 class="mansect"><a name="tag_20_112_16" id="tag_20_112_16"></a>APPLICATION USAGE</h4> 267 <blockquote> 268 <p>The default value for <b>-t</b>, <blank>, has different properties from, for example, <b>-t</b>"<space>". If a line 269 contains:</p> 270 <pre> 271 <tt><space><space>foo 272 </tt></pre> 273 <p>the following treatment would occur with default separation as opposed to specifically selecting a <space>:</p> 274 <center> 275 <table border="1" cellpadding="3" align="center"> 276 <tr valign="top"> 277 <th align="center"> 278 <p class="tent"><b>Field</b></p> 279 </th> 280 <th align="center"> 281 <p class="tent"><b>Default</b></p> 282 </th> 283 <th align="center"> 284 <p class="tent"><b>-t "<space>"</b></p> 285 </th> 286 </tr> 287 <tr valign="top"> 288 <td align="left"> 289 <p class="tent">1</p> 290 </td> 291 <td align="left"> 292 <p class="tent"><space><space>foo</p> 293 </td> 294 <td align="left"> 295 <p class="tent"><i>empty</i></p> 296 </td> 297 </tr> 298 <tr valign="top"> 299 <td align="left"> 300 <p class="tent">2</p> 301 </td> 302 <td align="left"> 303 <p class="tent"><i>empty</i></p> 304 </td> 305 <td align="left"> 306 <p class="tent"><i>empty</i></p> 307 </td> 308 </tr> 309 <tr valign="top"> 310 <td align="left"> 311 <p class="tent">3</p> 312 </td> 313 <td align="left"> 314 <p class="tent"><i>empty</i></p> 315 </td> 316 <td align="left"> 317 <p class="tent">foo</p> 318 </td> 319 </tr> 320 </table> 321 </center> 322 <p class="tent">The leading field separator itself is included in a field when <b>-t</b> is not used. For example, this command 323 returns an exit status of zero, meaning the input was already sorted:</p> 324 <pre> 325 <tt>sort -c -k 2 <<eof 326 y<tab>b 327 x<space>a 328 eof 329 </tt></pre> 330 <p class="tent">(assuming that a <tab> precedes the <space> in the current collating sequence). The field separator is 331 not included in a field when it is explicitly set via <b>-t</b>. This is historical practice and allows usage such as:</p> 332 <pre> 333 <tt>sort -t "|" -k 2n <<eof 334 Atlanta|425022|Georgia 335 Birmingham|284413|Alabama 336 Columbia|100385|South Carolina 337 eof 338 </tt></pre> 339 <p class="tent">where the second field can be correctly sorted numerically without regard to the non-numeric field separator.</p> 340 <p class="tent">The wording in the OPTIONS section clarifies that the <b>-b</b>, <b>-d</b>, <b>-f</b>, <b>-i</b>, <b>-n</b>, and 341 <b>-r</b> options have to come before the first sort key specified if they are intended to apply to all specified keys. The way it 342 is described in this volume of POSIX.1-2024 matches historical practice, not historical documentation. The results are unspecified 343 if these options are specified after a <b>-k</b> option.</p> 344 <p class="tent">The <b>-f</b> option might not work as expected in locales where there is not a one-to-one mapping between an 345 uppercase and a lowercase letter.</p> 346 <p class="tent">When using <i>sort</i> to process pathnames, it is recommended that LC_ALL, or at least LC_CTYPE and LC_COLLATE, 347 are set to POSIX or C in the environment, since pathnames can contain byte sequences that do not form valid characters in some 348 locales, in which case the utility's behavior would be undefined. In the POSIX locale each byte is a valid single-byte character, 349 and therefore this problem is avoided.</p> 350 <p class="tent">If the collating sequence of the current locale does not have a total ordering of all characters, since <i>sort</i> 351 <b>-u</b> suppresses lines with duplicate keys, it suppresses lines that collate equally but are not identical.</p> 352 </blockquote> 353 <h4 class="mansect"><a name="tag_20_112_17" id="tag_20_112_17"></a>EXAMPLES</h4> 354 <blockquote> 355 <ol> 356 <li class="tent">The following command sorts the contents of <b>infile</b> with the second field as the sort key: 357 <pre> 358 <tt>sort -k 2,2 infile 359 </tt></pre></li> 360 <li class="tent">The following command sorts, in reverse order, the contents of <b>infile1</b> and <b>infile2</b>, placing the 361 output in <b>outfile</b> and using the second character of the second field as the sort key (assuming that the first character of 362 the second field is the field separator): 363 <pre> 364 <tt>sort -r -o outfile -k 2.2,2.2 infile1 infile2 365 </tt></pre></li> 366 <li class="tent">The following command sorts the contents of <b>infile1</b> and <b>infile2</b> using the second non-<blank> 367 of the second field as the sort key: 368 <pre> 369 <tt>sort -k 2.2b,2.2b infile1 infile2 370 </tt></pre></li> 371 <li class="tent">The following command prints the System V password file (user database) sorted by the numeric user ID (the 372 third <colon>-separated field): 373 <pre> 374 <tt>sort -t : -k 3,3n /etc/passwd 375 </tt></pre></li> 376 <li class="tent">The following command prints the lines of the already sorted file <b>infile</b>, suppressing all but one 377 occurrence of lines having the same third field: 378 <pre> 379 <tt>sort -um -k 3.1,3.0 infile 380 </tt></pre></li> 381 </ol> 382 </blockquote> 383 <h4 class="mansect"><a name="tag_20_112_18" id="tag_20_112_18"></a>RATIONALE</h4> 384 <blockquote> 385 <p>Examples in some historical documentation state that options <b>-um</b> with one input file keep the first in each set of lines 386 with equal keys. This behavior was deemed to be an implementation artifact and was not standardized.</p> 387 <p class="tent">The <b>-z</b> option was omitted; it is not standard practice on most systems and is inconsistent with using 388 <i>sort</i> to sort several files individually and then merge them together. The text concerning <b>-z</b> in historical 389 documentation appeared to require implementations to determine the proper buffer length during the sort phase of operation, but not 390 during the merge.</p> 391 <p class="tent">The <b>-y</b> option was omitted because of non-portability. The <b>-M</b> option, present in System V, was omitted 392 because of non-portability in international usage.</p> 393 <p class="tent">An undocumented <b>-T</b> option exists in some implementations. It is used to specify a directory for intermediate 394 files. Implementations are encouraged to support the use of the <i>TMPDIR</i> environment variable instead of adding an option to 395 support this functionality.</p> 396 <p class="tent">The <b>-k</b> option was added to satisfy two objections. First, the zero-based counting used by <i>sort</i> is not 397 consistent with other utility conventions. Second, it did not meet syntax guideline requirements.</p> 398 <p class="tent">Historical documentation indicates that "setting <b>-n</b> implies <b>-b</b>". The description of <b>-n</b> 399 already states that optional leading <blank>s are tolerated in doing the comparison. If <b>-b</b> is enabled, rather than 400 implied, by <b>-n</b>, this has unusual side-effects. When a character offset is used in a column of numbers (for example, to sort 401 modulo 100), that offset is measured relative to the most significant digit, not to the column. Based upon a recommendation from 402 the author of the original <i>sort</i> utility, the <b>-b</b> implication has been omitted from this volume of POSIX.1-2024, and an 403 application wishing to achieve the previously mentioned side-effects has to code the <b>-b</b> flag explicitly.</p> 404 <p class="tent">Earlier versions of this standard allowed the <b>-o</b> option to appear after operands. Historical practice 405 allowed all options to be interspersed with operands. This version of the standard allows implementations to accept options after 406 operands but conforming applications should not use this form.</p> 407 <p class="tent">Earlier versions of this standard also allowed the <b>-</b><i>number</i> and <b>+</b><i>number</i> options. These 408 options are no longer specified by POSIX.1-2024 but may be present in some implementations.</p> 409 <p class="tent">Historical implementations produced a message on standard error when <b>-c</b> was specified and disorder was 410 detected, and when <b>-c</b> and <b>-u</b> were specified and a duplicate key was detected. An earlier version of this standard 411 contained wording that did not make it clear that this message was allowed and some implementations removed this message to be sure 412 that they conformed to the standard's requirements. Confronted with this difference in behavior, interactive users that wanted to 413 be sure that they got visual feedback instead of just exit code 1 could have used a command like:</p> 414 <pre> 415 <tt>sort -c file || echo disorder 416 </tt></pre> 417 <p class="tent">whether or not the <i>sort</i> utility provided a message in this case. But, it was not easy for a user to find 418 where the disorder or duplicate key occurred on implementations that do not produce a message, especially when some parts of the 419 input line were not part of the key and when one or more of the <b>-b</b>, <b>-d</b>, <b>-f</b>, <b>-i</b>, <b>-n</b>, or <b>-</b>r 420 options or <i>keydef</i> type modifiers were in use. POSIX.1-2024 requires a message to be produced in this case. POSIX.1-2024 also 421 contains the <b>-C</b> option giving users the ability to choose either behavior.</p> 422 <p class="tent">When a disorder or duplicate is found when the <b>-c</b> option is specified, some implementations print a message 423 containing the first line that is out of order or contains a duplicate key; others print a message specifying the line number of 424 the offending line. This standard allows either type of message.</p> 425 <p class="tent">The required further byte-by-byte comparison of lines that collate equally may have an impact on efficiency, but 426 this can be mitigated by only performing the additional comparison if the current locale's collating sequence does not have a total 427 ordering of all characters (if the implementation provides a way to query this) or by only performing the additional comparison if 428 the locale name associated with the <i>LC_COLLATE</i> category has an <tt>'@'</tt> modifier in the name (since 429 implementation-supplied locales without an <tt>'@'</tt> modifier have a total ordering of all characters — see XBD <a href= 430 "../basedefs/V1_chap07.html#tag_07_03_02"><i>7.3.2 LC_COLLATE</i></a> — and <a href= 431 "../utilities/localedef.html"><i>localedef</i></a> users are warned to follow the same convention). Note that if the implementation 432 provides a <i>stable sort</i> option as an extension (usually <b>-s</b>), the additional comparison should not be performed when 433 this option has been specified.</p> 434 </blockquote> 435 <h4 class="mansect"><a name="tag_20_112_19" id="tag_20_112_19"></a>FUTURE DIRECTIONS</h4> 436 <blockquote> 437 <p>If this utility is directed to create a new directory entry that contains any bytes that have the encoded value of a 438 <newline> character, implementations are encouraged to treat this as an error. A future version of this standard may require 439 implementations to treat this as an error.</p> 440 </blockquote> 441 <h4 class="mansect"><a name="tag_20_112_20" id="tag_20_112_20"></a>SEE ALSO</h4> 442 <blockquote> 443 <p><a href="../utilities/comm.html#"><i>comm</i></a> , <a href="../utilities/join.html#"><i>join</i></a> , <a href= 444 "../utilities/uniq.html#"><i>uniq</i></a></p> 445 <p class="tent">XBD <a href="../basedefs/V1_chap07.html#tag_07_03_02"><i>7.3.2 LC_COLLATE</i></a> , <a href= 446 "../basedefs/V1_chap08.html#tag_08"><i>8. Environment Variables</i></a> , <a href="../basedefs/V1_chap12.html#tag_12_02"><i>12.2 447 Utility Syntax Guidelines</i></a></p> 448 <p class="tent">XSH <a href="../functions/toupper.html#"><i>toupper</i></a></p> 449 </blockquote> 450 <h4 class="mansect"><a name="tag_20_112_21" id="tag_20_112_21"></a>CHANGE HISTORY</h4> 451 <blockquote> 452 <p>First released in Issue 2.</p> 453 </blockquote> 454 <h4 class="mansect"><a name="tag_20_112_22" id="tag_20_112_22"></a>Issue 6</h4> 455 <blockquote> 456 <p>IEEE PASC Interpretation 1003.2 #174 is applied, updating the DESCRIPTION of comparisons.</p> 457 <p class="tent">IEEE PASC Interpretation 1003.2 #168 is applied.</p> 458 </blockquote> 459 <h4 class="mansect"><a name="tag_20_112_23" id="tag_20_112_23"></a>Issue 7</h4> 460 <blockquote> 461 <p>Austin Group Interpretation 1003.1-2001 #027 is applied, clarifying that Guideline 9 of the Utility Syntax Guidelines does not 462 apply and noting that <tt>'+'</tt> may be recognized as an option delimiter.</p> 463 <p class="tent">Austin Group Interpretation 1003.1-2001 #120 is applied, clarifying the use of the <b>-c</b> option and introducing 464 the <b>-C</b> option.</p> 465 <p class="tent">XCU-ERN-81 is applied, modifying the description of the <b>-i</b> option.</p> 466 <p class="tent">SD5-XCU-ERN-97 is applied, updating the SYNOPSIS.</p> 467 <p class="tent">POSIX.1-2008, Technical Corrigendum 2, XCU/TC2-2008/0182 [963], XCU/TC2-2008/0183 [584], XCU/TC2-2008/0184 [510], 468 XCU/TC2-2008/0185 [962], XCU/TC2-2008/0186 [663], and XCU/TC2-2008/0187 [963] are applied.</p> 469 </blockquote> 470 <h4 class="mansect"><a name="tag_20_112_24" id="tag_20_112_24"></a>Issue 8</h4> 471 <blockquote> 472 <p>Austin Group Defect 251 is applied, encouraging implementations to disallow the creation of filenames containing any bytes that 473 have the encoded value of a <newline> character.</p> 474 <p class="tent">Austin Group Defect 862 is applied, adding <i>TMPDIR</i> to the ENVIRONMENT VARIABLES section.</p> 475 <p class="tent">Austin Group Defect 1070 is applied, requiring that any lines of input that collate equally when comparing them as 476 whole lines are further compared byte-by-byte using the collating sequence for the POSIX locale.</p> 477 <p class="tent">Austin Group Defect 1122 is applied, changing the description of <i>NLSPATH .</i></p> 478 </blockquote> 479 <div class="box"><em>End of informative text.</em></div> 480 <hr> 481 <p> </p> 482 <a href="#top"><span class="topOfPage">return to top of page</span></a><br> 483 <hr size="2" noshade> 484 <center><font size="2">UNIX® is a registered Trademark of The Open Group.<br> 485 POSIX™ is a Trademark of The IEEE.<br> 486 Copyright © 2001-2024 The IEEE and The Open Group, All Rights Reserved<br> 487 [ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href= 488 "../functions/contents.html">XSH</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../xrat/contents.html">XRAT</a> 489 ]</font></center> 490 <hr size="2" noshade> 491 <div class="NAVHEADER"> 492 <table summary="Header navigation table" class="nav" width="100%" border="0" cellpadding="0" cellspacing="0"> 493 <tr class="nav"> 494 <td class="nav" width="15%" align="left" valign="bottom"><a href="../utilities/sleep.html" accesskey="P"><<< 495 Previous</a></td> 496 <td class="nav" width="70%" align="center" valign="bottom"><a href="contents.html">Home</a></td> 497 <td class="nav" width="15%" align="right" valign="bottom"><a href="../utilities/split.html" accesskey="N">Next 498 >>></a></td> 499 </tr> 500 </table> 501 <hr align="left" width="100%"></div> 502 </body> 503 </html>