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 3.12 Shell Execution Environment A shell execution environment consists of the following: - Open files inherited upon invocation of the shell, plus open files controlled by exec. - Working Directory as set by cd (see 4.5). - File Creation Mask set by umask (see 4.67). - Current traps set by trap (see 3.14.13). - Shell parameters that are set by variable assignment (see set in 3.14.11) or from the POSIX.1 {8} environment inherited by the shell when it begins (see export in 3.14.8). - Shell functions (see 3.9.5.) - Options turned on at invocation or by set. - Process IDs of the last commands in asynchronous lists known to 1 this shell environment; see 3.9.3.1. 1 Utilities other than the special built-ins (see 3.14) shall be invoked in a separate environment that consists of the following. The initial value of these objects shall be the same as that for the parent shell, except as noted below. - Open files inherited on invocation of the shell, open files controlled by the exec special built-in (see 3.14.6), plus any modifications and additions specified by any redirections to the utility. - Current working directory. - File creation mask. - If the utility is a shell script, traps caught by the shell shall be set to the default values and traps ignored by the shell shall be set to be ignored by the utility. If the utility is not a shell script, the trap actions (default or ignore) shall be mapped into the appropriate signal handling actions for the utility. - Variables with the export attribute, along with those explicitly exported for the duration of the command, shall be passed to the utility as POSIX.1 {8} environment variables. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 3.12 Shell Execution Environment 289 P1003.2/D11.2 INFORMATION TECHNOLOGY--POSIX The environment of the shell process shall not be changed by the utility unless explicitly specified by the utility description (for example, cd and umask). A subshell environment shall be created as a duplicate of the shell environment, except that signal traps set by that shell environment shall 1 be set to the default values. Changes made to the subshell environment 1 shall not affect the shell environment. Command substitution, commands that are grouped with parentheses, and asynchronous lists shall be executed in a subshell environment. Additionally, each command of a multicommand pipeline is in a subshell environment; as an extension, however, any or all commands in a pipeline may be executed in the current environment. All other commands shall be executed in the current shell environment. BEGIN_RATIONALE 3.12.0.1 Shell Execution Environment 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) Some systems have implemented the last stage of a pipeline in the current environment so that commands such as _c_o_m_m_a_n_d | read foo set variable foo in the current environment. It was decided to allow this extension, but not require it; therefore, a shell programmer should consider a pipeline to be in a subshell environment, but not depend on it. The previous description of execution environment failed to mention that each command in a multiple command pipeline could be in a subshell execution environment. For compatibility with some existing shells, the wording was phrased to allow an implementation to place any or all commands of a pipeline in the current environment. However, this means that a POSIX application must assume each command is in a subshell environment, but not depend on it. The wording about shell scripts is meant to convey the fact that describing ``trap actions'' can only be understood in the context of the shell command language. Outside this context, such as in a C-language program, signals are the operative condition, not traps. END_RATIONALE Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 290 3 Shell Command Language Part 2: SHELL AND UTILITIES P1003.2/D11.2 3.13 Pattern Matching Notation The pattern matching notation described in this clause is used to specify patterns for matching strings in the shell. Historically, pattern matching notation is related to, but slightly different from, the regular expression notation described in 2.8. For this reason, the description of the rules for this pattern matching notation are based on the description of regular expression notation. BEGIN_RATIONALE 3.13.0.1 Pattern Matching Notation 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) Pattern matching is a simpler concept and has a simpler syntax than regular expressions, as the former is generally used for the manipulation of file names, which are relatively simple collections of characters, while the latter is generally used to manipulate arbitrary text strings of potentially greater complexity. However, some of the basic concepts are the same, so this clause points liberally to the detailed descriptions in 2.8. END_RATIONALE 3.13.1 Patterns Matching a Single Character The following _p_a_t_t_e_r_n_s _m_a_t_c_h_i_n_g _a _s_i_n_g_l_e-_c_h_a_r_a_c_t_e_r match a single character: _o_r_d_i_n_a_r_y _c_h_a_r_a_c_t_e_r_s, _s_p_e_c_i_a_l _p_a_t_t_e_r_n _c_h_a_r_a_c_t_e_r_s, and _p_a_t_t_e_r_n _b_r_a_c_k_e_t _e_x_p_r_e_s_s_i_o_n_s. The pattern bracket expression also shall match a single collating element. An ordinary character is a pattern that shall match itself. It can be any character in the supported character set except for NUL, those 1 special shell characters in 3.2 that require quoting, and the following 1 three special pattern characters. Matching shall be based on the bit 1 pattern used for encoding the character, not on the graphic 1 representation of the character. If any character (ordinary, shell 1 special, or pattern special) is quoted, that pattern shall match the 1 character itself. The shell special characters always require quoting. 1 When unquoted and outside a bracket expression, the following three 1 characters shall have special meaning in the specification of patterns: 1 ? A question-mark is a pattern that shall match any character. * An asterisk is a pattern that shall match multiple characters, as described in 3.13.2. Copyright c 1991 IEEE. All rights reserved. This is an unapproved IEEE Standards Draft, subject to change. 3.13 Pattern Matching Notation 291