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 This would not work for the versions of these utilities in earlier drafts due to the way processing of trailing slashes was specified. Consideration was given to leaving processing unspecified if there were trailing slashes, but this cannot be done; the POSIX.1 {8} definition of pathname allows trailing slashes. The basename and dirname utilities have to specify consistent handling for all valid pathnames. Since the definition of _p_a_t_h_n_a_m_e in 2.2.2.102 specifies implementation- defined behavior for pathnames starting with two slash characters, Draft 11 has been changed to specify similar implementation-defined behavior for the basename and dirname utilities. On implementations where the pathname // is always treated the same as the pathname /, the functionality required by Draft 10 meets all of the Draft 11 requirements. END_RATIONALE 4.19 echo - Write arguments to standard output 4.19.1 Synopsis echo [_s_t_r_i_n_g ...] 4.19.2 Description The echo utility shall write its arguments to standard output, followed by a character. If there are no arguments, only the character shall be written. 4.19.3 Options The echo utility shall not recognize the -- argument in the manner specified by utility syntax guideline 10 in 2.10.2; -- shall be recognized as a string operand. Implementations need not support any options. 4.19.4 Operands The following operands shall be supported by the implementation: Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.19 echo - Write arguments to standard output 475 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX _s_t_r_i_n_g A string to be written to standard output. If the first operand is "-n" or if any of the operands contain a backslash (\) character, the results are implementation defined. 4.19.5 External Influences 4.19.5.1 Standard Input None. 4.19.5.2 Input Files None. 4.19.5.3 Environment Variables The following environment variables shall affect the execution of echo: 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_MESSAGES This variable shall determine the language in which diagnostic messages should be written. 4.19.5.4 Asynchronous Events Default. 4.19.6 External Effects 4.19.6.1 Standard Output The echo utility arguments shall be separated by single s and a character shall follow the last argument. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 476 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 4.19.6.2 Standard Error Used only for diagnostic messages. 4.19.6.3 Output Files None. 4.19.7 Extended Description None. 4.19.8 Exit Status The echo utility shall exit with one of the following values: 0 Successful completion. >0 An error occurred. 4.19.9 Consequences of Errors Default. BEGIN_RATIONALE 4.19.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 As specified by this standard, echo writes its arguments in the simplest of ways. The two different historical versions of echo vary in fatal incompatible ways. The BSD echo checks the first argument for the string "-n", which causes it to suppress the character that would otherwise follow the final argument in the output. The System V echo does not support any options, but allows escape sequences within its operands: \a Write an character. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.19 echo - Write arguments to standard output 477 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX \b Write a character. \c Suppress the character that otherwise follows the final argument in the output. All characters following the \c in the arguments are ignored. \f Write a character. \n Write a character. \r Write a character. \t Write a character. \v Write a character. \\ Write a backslash character. \0_n_u_m Write an 8-bit value that is the 1-, 2-, or 3-digit octal number _n_u_m. It is not possible to use echo portably across these two implementations unless both -n (as the first argument) and escape sequences are omitted. The printf utility (see 4.50) can be used to portably emulate any of the traditional behaviors of the echo utility as follows: - The System V echo is equivalent to: printf "%b\n" "$*" - The BSD echo is equivalent to: if [ "X$1" = "X-n" ] then shift printf "%s" "$*" else printf "%s\n" "$*" fi The echo utility does not support utility syntax guideline 10 because existing applications depend on echo to echo _a_l_l of its arguments, except for the -n option in the BSD version. New applications are encouraged to use printf instead of echo. The echo utility has not been made obsolescent because of its extremely widespread use in existing applications. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 478 4 Execution Environment Utilities Part 2: SHELL AND UTILITIES P1003.2/D11.2 _H_i_s_t_o_r_y__o_f__D_e_c_i_s_i_o_n_s__M_a_d_e In Draft 8, an attempt was made to merge the extensions of BSD and System V, supporting both -n and escape sequences. During initial ballot resolution, a -e option was proposed to enable the escape conventions. Both attempts failed, as there are historical scripts that would be broken by any attempt at reconciliation. Therefore, in Draft 9 only the simplest version of echo is presented. Implementation-defined extensions on BSD and System V will keep historical applications content. Portable applications that wish to do prompting without s or that could possibly be expecting to echo a "-n", should use the new printf utility (see 4.50), derived from the Ninth Edition. The LC_CTYPE variable is not cited because echo, as specified here, does not need to understand the characters in its arguments. The System V and BSD implementations might need to be sensitive to it because of their extensions. END_RATIONALE 4.20 ed - Edit text 4.20.1 Synopsis ed [-p _s_t_r_i_n_g] [-s] [_f_i_l_e] _O_b_s_o_l_e_s_c_e_n_t _V_e_r_s_i_o_n: ed [-p _s_t_r_i_n_g] [-] [_f_i_l_e] 4.20.2 Description The ed utility is a line-oriented text editor that shall use two modes: _c_o_m_m_a_n_d _m_o_d_e and _i_n_p_u_t _m_o_d_e. In command mode the input characters shall be interpreted as commands, and in input mode they shall be interpreted as text. See 4.20.7. 4.20.3 Options The ed utility shall conform to the utility argument syntax guidelines described in 2.10.2, except for its nonstandard usage of - in the obsolescent version. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 4.20 ed - Edit text 479