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] P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX character is discarded. (9) If the previous character was part of a word, the current character is appended to that word. (10) If the current character is a #, it and all subsequent characters up to, but excluding, the next are discarded as a comment. The that ends the line is not considered part of the comment. (11) The current character is used as the start of a new word. Once a token is delimited, it shall be categorized as required by the grammar in 3.10. BEGIN_RATIONALE 3.3.1 Token Recognition 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) The (3) rule about combining characters to form operators is not meant to 1 preclude systems from extending the shell language when characters are 1 combined in otherwise invalid ways. Portable applications cannot use 1 invalid combinations and test suites should not penalize systems that 1 take advantage of this fact. For example, the unquoted combination |& is 1 not valid in a POSIX.2 script, but has a specific KornShell meaning. 1 The (10) rule about # as the current character is the first in the sequence in which a new token is being assembled. The # starts a comment only when it is at the beginning of a token. This rule is also written to indicate that the search for the end-of-comment does not consider escaped specially, so that a comment cannot be continued to the next line. END_RATIONALE 3.4 Reserved Words Reserved words are words that have special meaning to the shell. (See 3.9.) The following words shall be recognized as reserved words: ! elif fi in while case else for then {4) do esac if until } done Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 226 3 Shell Command Language Part 2: SHELL AND UTILITIES P1003.2/D11.2 This recognition shall occur only when none of the characters are quoted and when the word is used as: (1) The first word of a command (2) The first word following one of the reserved words other than case, for, or in (3) The third word in a case or for command (only in is valid in this case) See the grammar in 3.10. The following words may be recognized as reserved words on some systems (when none of the characters are quoted), causing unspecified results: function select [[ ]] 2 Words that are the concatenation of a name and a colon (:) are reserved; their use produces unspecified results. BEGIN_RATIONALE 3.4.1 Reserved Words 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) All reserved words are recognized syntactically as such in the contexts described. However, it is useful to point out that in is the only meaningful reserved word after a case or for; similarly, in is not meaningful as the first word of a simple command. Reserved words are recognized only when they are delimited (i.e., meet the definition of _w_o_r_d; see 3.1.16), whereas operators are themselves delimiters. For instance, ( and ) are control operators, so that no is needed in (list). However, { and } are reserved words in { list;}, so that in this case the leading and semicolon are required. __________ 4) In some historical systems, the curly braces are treated as control operators. To assist in future standardization activities, portable applications should avoid using unquoted braces to represent the characters themselves. It is possible that a future version of POSIX.2 may require this, although probably not for the often-used find {} construct. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 3.4 Reserved Words 227 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX The list of unspecified reserved words is from the KornShell, so portable applications cannot use them in places a reserved word would be recognized. This list contained time in earlier drafts, but it was 2 removed when the time utility was selected for the UPE. 2 There was a strong argument for promoting braces to operators (instead of reserved words), so they would be syntactically equivalent to subshell operators. Concerns about compatibility outweighed the advantages of this approach. Nevertheless, portable applications should consider quoting { and } when they represent themselves. The restriction on ending a name with a colon is to allow future implementations that support named labels for flow control. See the rationale for break (3.14.1.1). END_RATIONALE 3.5 Parameters and Variables A parameter can be denoted by a name, a number, or one of the special characters listed in 3.5.2. A variable is a parameter denoted by a name. A parameter is set if it has an assigned value (null is a valid value). Once a variable is set, it can only be unset by using the unset special built-in command. 3.5.1 Positional Parameters A positional parameter is a parameter denoted by the decimal value represented by one or more digits, other than the single digit 0. When a positional parameter with more than one digit is specified, the application shall enclose the digits in braces (see 3.6.2). Positional parameters are initially assigned when the shell is invoked (see sh in 4.56), temporarily replaced when a shell function is invoked (see 3.9.5), and can be reassigned with the set special built-in command. BEGIN_RATIONALE 3.5.1.1 Positional Parameters 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) The digits denoting the positional parameters are always interpreted as a decimal value, even if there is a leading zero. END_RATIONALE Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 228 3 Shell Command Language