IEEE P1003.2 Draft 11.2 - September 1991 Copyright (c) 1991 by the Institute of Electrical and Electronics Engineers, Inc. 345 East 47th Street New York, NY 10017, USA All rights reserved as an unpublished work. This is an unapproved and unpublished IEEE Standards Draft, subject to change. The publication, distribution, or copying of this draft, as well as all derivative works based on this draft, is expressly prohibited except as set forth below. Permission is hereby granted for IEEE Standards Committee participants to reproduce this document for purposes of IEEE standardization activities only, and subject to the restrictions contained herein. Permission is hereby also granted for member bodies and technical committees of ISO and IEC to reproduce this document for purposes of developing a national position, subject to the restrictions contained herein. Permission is hereby also granted to the preceding entities to make limited copies of this document in an electronic form only for the stated activities. The following restrictions apply to reproducing or transmitting the document in any form: 1) all copies or portions thereof must identify the document's IEEE project number and draft number, and must be accompanied by this entire notice in a prominent location; 2) no portion of this document may be redistributed in any modified or abridged form without the prior approval of the IEEE Standards Department. Other entities seeking permission to reproduce this document, or any portion thereof, for standardization or other activities, must contact the IEEE Standards Department for the appropriate license. Use of information contained in this unapproved draft is at your own risk. IEEE Standards Department Copyright and Permissions 445 Hoes Lane, P.O. Box 1331 Piscataway, NJ 08855-1331, USA +1 (908) 562-3800 +1 (908) 562-1571 [FAX] Part 2: SHELL AND UTILITIES P1003.2/D11.2 END_RATIONALE 4.71 wc - Word, line, and byte count 4.71.1 Synopsis wc [-clw] [_f_i_l_e ...] 4.71.2 Description The wc utility shall read one or more input files and, by default, write the number of s, words, and bytes contained in each input file to the standard output. The utility also shall write a total count for all named files, if more than one input file is specified. The wc utility shall consider a _w_o_r_d to be a nonzero-length string of characters delimited by white space. 4.71.3 Options The wc utility shall conform to the utility argument syntax guidelines described in 2.10.2. The following options shall be supported by the implementation: -c Write to the standard output the number of bytes in each input file. -l Write to the standard output the number of s in each input file. -w Write to the standard output the number of words in each input file. When any option is specified, wc shall report only the information requested by the specified option(s). Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.71 wc - Word, line, and byte count 795 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX 4.71.4 Operands The following operand shall be supported by the implementation: _f_i_l_e A pathname of an input file. If no _f_i_l_e operands are specified, the standard input shall be used. 4.71.5 External Influences 4.71.5.1 Standard Input The standard input shall be used only if no _f_i_l_e operands are specified. See Input Files. 4.71.5.2 Input Files The input files may be of any type. 4.71.5.3 Environment Variables The following environment variables shall affect the execution of wc: LANG This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_) do not specify a locale. See 2.6. LC_ALL This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_. LC_CTYPE This variable shall determine the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments and input files) and which characters are defined as ``white space'' characters. LC_MESSAGES This variable shall determine the language in which messages should be written. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 796 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 4.71.5.4 Asynchronous Events Default. 4.71.6 External Effects 4.71.6.1 Standard Output By default, the standard output shall contain a line for each input file of the form: "%d %d %d %s\n", <_n_e_w_l_i_n_e_s>, <_w_o_r_d_s>, <_b_y_t_e_s>, <_f_i_l_e> If any options are specified and the -l option is not specified, the number of s shall not be written. If any options are specified and the -w option is not specified, the number of words shall not be written. If any options are specified and the -c option is not specified, the number of bytes shall not be written. If no input _f_i_l_e operands are specified, no name shall be written and no s preceding the pathname shall be written. If more than one input _f_i_l_e operand is specified, an additional line shall be written, of the same format as the other lines, except that the word total (in the POSIX Locale) shall be written instead of a pathname and the total of each column shall be written as appropriate. Such an additional line, if any, shall be written at the end of the output. 4.71.6.2 Standard Error Used only for diagnostic messages. 4.71.6.3 Output Files None. 4.71.7 Extended Description None. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.71 wc - Word, line, and byte count 797 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX 4.71.8 Exit Status The wc utility shall exit with one of the following values: 0 Successful completion. >0 An error occurred. 4.71.9 Consequences of Errors Default. BEGIN_RATIONALE 4.71.10 Rationale. (_T_h_i_s _s_u_b_c_l_a_u_s_e _i_s _n_o_t _a _p_a_r_t _o_f _P_1_0_0_3._2) _E_x_a_m_p_l_e_s_,__U_s_a_g_e None. _H_i_s_t_o_r_y__o_f__D_e_c_i_s_i_o_n_s__M_a_d_e The output file format pseudo-_p_r_i_n_t_f() string was derived from the HP-UX version of wc; the System V version: "%7d%7d%7d %s\n" produces possibly ambiguous and unparsable results for very large files, as it assumes no number will exceed six digits. Some historical implementations use only , , and as word separators. The equivalent of the C Standard {7} _i_s_s_p_a_c_e() function is more appropriate. The -c option stands for ``character'' count, even though it counts bytes. This stems from the sometimes erroneous historical view that bytes and characters are the same size. Earlier drafts only specified the results when input files were text files. The current specification more closely matches existing practice. (Bytes, words, and _s are counted separately and the results are written when an end-of-file is detected.) Historical implementations of the wc utility only accepted one argument to specify the options -c, -l, and -w. Some of them also had multiple occurrences of an option cause the corresponding count to be output multiple times and having the order of specification of the options Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 798 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 affect the order of the fields on output, but did not document either of these. Because common usage either specifies no options or only one option and because none of this was documented, the changes required by this standard should not break many existing applications (and does not break any historical portable applications.) END_RATIONALE 4.72 xargs - Construct argument list(s) and invoke utility 4.72.1 Synopsis xargs [-t] [-n _n_u_m_b_e_r [-x] ] [-s _s_i_z_e] [_u_t_i_l_i_t_y [_a_r_g_u_m_e_n_t ...]] 4.72.2 Description The xargs utility shall construct a command line consisting of the _u_t_i_l_i_t_y and _a_r_g_u_m_e_n_t operands specified followed by as many arguments read in sequence from standard input as will fit in length and number constraints specified by the options. The xargs utility shall then invoke the constructed command line and wait for its completion. This sequence shall be repeated until an end-of-file condition is detected on standard input or an invocation of a constructed command line returns an 1 exit status of 255. 1 Arguments in the standard input shall be separated by unquoted s, or unescaped s or s. A string of zero or more nondouble-quote (") and non- characters can be quoted by enclosing them in double-quotes. A string of zero or more nonapostrophe (') and non- characters can be quoted by enclosing them in apostrophes. Any unquoted character can be escaped by preceding it with a backslash. The _u_t_i_l_i_t_y shall be executed one or more times until the end-of-file is reached. The results are unspecified if the utility named by _u_t_i_l_i_t_y attempts to read from its standard input. The generated command line length shall be the sum of the size in bytes of the utility name and each argument treated as strings, including a null byte terminator for each of these strings. The xargs utility shall limit the command line length such that when the command line is invoked, the combined argument and environment lists (see the _e_x_e_c family of functions in POSIX.1 {8} 3.1.2) shall not exceed {ARG_MAX}-2048 bytes. Within this constraint, if neither the -n nor the -s option is specified, the default command line length shall be at least {LINE_MAX}. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.72 xargs - Construct argument list(s) and invoke utility 799